max_
max_

Reputation: 24521

Set NavigationBarButton Title Text Color

I just wanted to know if it is possible to set the NavigationBarButton's title's text color, and if so how?

Upvotes: 0

Views: 563

Answers (2)

PengOne
PengOne

Reputation: 48373

I did the following. In -(id)init add:

    // CUSTOMIZE NAVIGATION BAR TITLE COLOR
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 44.0)];
[label setBackgroundColor:[UIColor clearColor]];
[label setFont:[UIFont boldSystemFontOfSize:20.0]];
[label setAdjustsFontSizeToFitWidth:YES];
[label setTextAlignment:UITextAlignmentCenter];
[[self navigationItem] setTitleView:label];
[label release];

Then in -(void)viewDidLoad add:

    [[[self navigationItem] titleView] setText:@"TITLE"];
[[[self navigationItem] titleView] setTextColor:titleColor];

I put them like this so that I could change the title and titleColor based on how one got to this screen. If you don't need to customize, then put it all in init or viewDidLoad. Doing it like this I get a warning that "UIView may not respond to '-setText'" even though it all works fine.

Upvotes: 1

Felix
Felix

Reputation: 35394

You can set an image for the UIBarButtonItem and thus fully customize the title text.

Upvotes: 0

Related Questions