Dev Singh
Dev Singh

Reputation: 39

How to change font size of title in iphone?

this is the code ,this will show the default size, i want to change the font size of the title becoz this title is too big n not showing the whole only "Cook Great Indian..." is showing...pl let me help out

- (void)viewDidLoad {

    self.title = @"Cook Great Indian Recipes";
}

Upvotes: 2

Views: 7067

Answers (2)

kviksilver
kviksilver

Reputation: 3854

Try setting custom label for title label:

    self.title = @"Cook Great Indian Recipes";
    CGRect frame = CGRectMake(0, 0, [self.title sizeWithFont:[UIFont boldSystemFontOfSize:20.0]].width, 44);
    UILabel *label = [[UILabel alloc] initWithFrame:frame];
    label.backgroundColor = [UIColor clearColor];
    label.font = [UIFont boldSystemFontOfSize:17.0];
    label.textAlignment = UITextAlignmentCenter;
    self.navigationItem.titleView = label;
    label.text = self.title;
    [label release];

Upvotes: 12

EmptyStack
EmptyStack

Reputation: 51374

You can not change the font of title. Instead create a UILabel with your own customization and assign it as navigationItem's titleView.

UILabel *titleLbl = [[UILabel alloc] init];
label.frame = CGRectMake(...
label.font = [UIFont ...
// And the other things
self.navigationItem.titleView = titleLbl;
[titleLbl release];

Upvotes: 3

Related Questions