Prakash Desai
Prakash Desai

Reputation: 511

App get crash while changing font

This is how I change background of navigation bar and try to set font like this

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];

What am I doing wrong? I checked many answer but this is how they set font.

Upvotes: 0

Views: 463

Answers (2)

Satheesh
Satheesh

Reputation: 11276

Assign font like this:

 tmpTitleLabel.font=[UIFont systemFontOfSize:12];

or use setFont: method

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

Upvotes: 2

taskinoor
taskinoor

Reputation: 46037

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

This is wrong. You are using getter instead of setter. You missed the set part and capital F.

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

Or use dot syntax like this:

tmpTitleLabel.font = [UIFont systemFontOfSize:12];

Upvotes: 3

Related Questions