Kiran Kulkarni
Kiran Kulkarni

Reputation: 1504

How to change the font of UINavigation Controller Header.?

I wanted to know how can we change the font size of the title of a view while using UINavigationController.., Thanks in advance

Upvotes: 0

Views: 441

Answers (3)

Deepesh
Deepesh

Reputation: 643

change the font and title...

+(void) setNavigationTitle:(NSString *) title ForNavigationItem:(UINavigationItem *) navigationItem { UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 200.0f, 44.0f)];

UILabel *titleLbl = [[UILabel alloc]

initWithFrame:CGRectMake(0.0f, 6.0f, 200.0f,30.0f)];

[titleLbl setFont:[UIFont fontWithName:@"BellCent NamNum BT"

size:24.0]];

[titleLbl setBackgroundColor:[UIColor clearColor]];
[titleLbl setTextAlignment:UITextAlignmentCenter];

[titleLbl setTextColor:UIColorFromRedGreenBlue(35,134,192)];
[titleLbl setShadowColor:UIColorFromRedGreenBlue(186,186,186)];
[titleLbl setShadowOffset:CGSizeMake(1.0f, 1.0f)];

[titleLbl setText:title];

  [view addSubview:titleLbl];

[navigationItem setTitleView:view];
[titleLbl release];

 }

Upvotes: 0

Alex Terente
Alex Terente

Reputation: 12036

    self.title = @"";
    UILabel *myNavigationTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 5, self.view.frame.size.width, 33)];
    myNavigationTitleLabel.textColor = [UIColor whiteColor];
    myNavigationTitleLabel.backgroundColor = [UIColor clearColor];
    myNavigationTitleLabel.text = @"my Custom title";
    myNavigationTitleLabel.textAlignment = UITextAlignmentCenter;
    myNavigationTitleLabel.font = [UIFont fontWithName:@"Arial" size:17];
    [self.navigationController.navigationBar addSubview:myNavigationTitleLabel];
    [myNavigationTitleLabel release];

Note that if you have landscape interface orientation you need to set new frame for the myNavigationTitleLabel.

Upvotes: 1

EmptyStack
EmptyStack

Reputation: 51374

You can not directly change it. Create a custom UILabel, or any other view, with the style you want and assign it as self.navigationItem.titleView, instead.

Upvotes: 1

Related Questions