0

这就是我更改导航栏背景并尝试设置这样的字体的方式

UIImage *image = [UIImage imageNamed:@"header.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];        

UILabel *tmpTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(120, 0, 100, 40)];
[tmpTitleLabel font:[UIFont systemFontOfSize:12]];  
// APP CRASH (IF I ERASH THIS ABOVE LINE THEN TITLE GET DISPLAYED AS FACEBOOK )

tmpTitleLabel.text = @"Facebook";
tmpTitleLabel.backgroundColor = [UIColor clearColor];

tmpTitleLabel.textColor = [UIColor whiteColor];

CGRect applicationFrame = CGRectMake(0, 0, 300, 40);
UIView * newView = [[[UIView alloc] initWithFrame:applicationFrame] autorelease];
[newView addSubview:imageView];
[newView addSubview:tmpTitleLabel];

[self.navigationController.navigationBar addSubview:newView];

我究竟做错了什么?我检查了很多答案,但这就是他们设置字体的方式。

4

2 回答 2

3

[tmpTitleLabel font:[UIFont systemFontOfSize:12]];

这是错误的。您正在使用 getter 而不是 setter。你错过了set部分和资本F

[tmpTitleLabel setFont:[UIFont systemFontOfSize:12]];
               ^^^^ 

或者像这样使用点语法:

tmpTitleLabel.font = [UIFont systemFontOfSize:12];
于 2013-04-19T07:48:05.827 回答
2

像这样分配字体:

 tmpTitleLabel.font=[UIFont systemFontOfSize:12];

或使用 setFont: 方法

 [tmpTitleLabel setFont:[UIFont systemFontOfSize:12]];
于 2013-04-19T07:48:34.943 回答