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

2

次のようにフォントを割り当てます。

 tmpTitleLabel.font=[UIFont systemFontOfSize:12];

または setFont: メソッドを使用します

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