Reputation: 9120
I add it a UINavigationBar on interface builder on my story board but I want to change the color and title of the UINavigationBar programmatically but it doesn't work. Here is my code:
self.navigationController.navigationBar.tintColor = [UIColor redColor];
self.navigationItem.title = @"New Title";
Any of you knows why this happening or a way around this?
I'll really appreciate your help.
Upvotes: 0
Views: 148
Reputation: 513
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:33.0/255.0 green:30.0/255.0 blue:94.0/255.0 alpha:1.0];
self.navigationController.navigationBar.titleTextAttributes = [NSDictionary dictionaryWithObject:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
put this in the view did load method. first one is for the navigation bar tint color and the second one is for the title font color.
Upvotes: 0
Reputation: 1207
you can also use these code to change the navigationbar in global.
[[UINavigationBar appearance] setBarTintColor:RGB(248, 248, 248)];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:COLOR_NAV_GLOBAL}];
[[UINavigationBar appearance] setBackIndicatorImage:[[UIImage imageNamed:@"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[[UIImage imageNamed:@"nav_back"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
Upvotes: 0
Reputation: 5
try this code
self.navigationController.navigationBar.titleTextAttributes = @{NSForegroundColorAttributeName:[UIColor blueColor]};
if you want to change navigation bar background color, use
self.navigationController.navigationBar.barTintColor
Upvotes: 1
Reputation: 2809
Try:
self.navigationController.navigationBar.barTintColor = [UIColor redColor];
These kinds of things can also be done in interface builder when you have access to the reference (and previewed)
Upvotes: 1