8
votes

I am new to iOS development, I facing a strange problem. In viewDidLoad

I had written a code like this

self.navigationController.navigationBar.backgroundColor= [UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0];

this is working fine and changed the navigation bar background color, the problem is in the top of the navigation bar there is white bar showing (that has Carrier, Battery, time), I want that background color also changed... so I tried the below code

[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0]];

But nothing changed, it is showing same white background color, I would like to know whats the mistake I am doing

2
[[UINavigationBar appearance] setBarTintColor:color]CSmith
No it is not working already I had tried that..Subramanian Raj
It works, you must ensure you set your appearance proxy before you load view controllers, e.g. in your app delegate applicationDidFinishLaunching methodCSmith
In AppDelegate I had given like this - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0]]; [[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0]];Subramanian Raj

2 Answers

11
votes

Try this,

[[UINavigationBar appearance] setBarTintColor:[UIColor yellowColor]];

or

self.navigationController.navigationBar.barTintColor = [UIColor blueColor];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
self.navigationController.navigationBar.translucent = NO;

and

[self.navigationController.navigationBar setBarStyle:UIStatusBarStyleLightContent];
0
votes

You should use the barTintColor property in order to change the navigation bar background color and also the status bar background color.

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:189.0/255.0 green:105.0/255 blue:105.0/255 alpha:1.0]];