Jonathan Thurft Jonathan Thurft - 1 year ago 90
iOS Question

How to change UINavigationBar background color from the AppDelegate

I know how to change the

background image by doing

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nabbar"] forBarMetrics:UIBarMetricsDefault];

and I know how to set the bar to different colors within each
..... Now I want to change the background color without using an image to a solid color from the
app delegate
. I do not want to set it each time from each view and I do not want to write a

I tried
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:33/255.0 green:34/255.0 blue:36/255.0 alpha:1.0]];
but I doesn't work and I cant find a code anywhere that works in the app delegate.

Could anyone please point me in the right direction?

Answer Source

You can use [[UINavigationBar appearance] setTintColor:myColor];

Since iOS 7 you need to set [[UINavigationBar appearance] setBarTintColor:myColor]; and also [[UINavigationBar appearance] setTranslucent:NO].

[[UINavigationBar appearance] setBarTintColor:myColor];
[[UINavigationBar appearance] setTranslucent:NO];