Jonathan Thurft Jonathan Thurft - 4 months ago 29
iOS Question

How to change UINavigationBar background color from the AppDelegate

I know how to change the

UINavigationBar
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
Views
..... 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
CGRect
.

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

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];