Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 538
Jonathan Thurft Avatar asked Jun 09 '13 22:06

Jonathan Thurft


People also ask

How do I use the navigation bar in Xcode?

To add a navigation bar to your interface, the following steps are required: Set up Auto Layout rules to govern the position of the navigation bar in your interface. Create a root navigation item to supply the initial title. Configure a delegate object to handle user interactions with the navigation bar.


1 Answers

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]; 
like image 85
Seb Thiebaud Avatar answered Oct 16 '22 23:10

Seb Thiebaud