Xi Zhang Xi Zhang - 1 year ago 41
iOS Question

Is there a place to set the UINavigationBar's default color?

I am a new iOS developer working on a project that created by an ex-employee. Currently all the navigation bar is black, and I need to change them to the default blue color. So far I have figured out this line:

[self.navigationController.navigationBar setTintColor:[[UIColor colorWithHue:0.6 saturation:0.33 brightness: 0.65 alpha:1.0] autorelease]];

It worked, but I don't think it's the right way to do it. I have created a new screen too and the color is blue, so I figure there must be a setting in some place. In the xib file the Top Bar is none, and we have this code in viewDidLoad

if (self.navigationController.navigationBar.isHidden) {
[self.navigationController setNavigationBarHidden:NO animated:YES];
else {
[self.navigationController setNavigationBarHidden:NO animated:NO];

The question is: is there a place I can set the default color? or I have to do it programmatically.

Answer Source

When you create your Navigation Controller, you can set the color for the bar:

navigationController = [[UINavigationController alloc] initWithRootViewController: mainView];
self.navigationController.navigationBar.tintColor = [UIColor <whatever color you want>];

Or if you just want the default blue color:

self.navigationController.navigationBar.barStyle = UIBarStyleDefault;