IOS navigation bar background color

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

I wrote 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 works fine and changed the background color on the navigation bar, the problem at the top of the navigation bar shows a white bar showing (with Carrier, Battery, time), I want the background color to also change ... so I tried the code below

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

But nothing has changed, it shows the same white background color, I would like to know what is the mistake I'm making

+6
source share
2 answers

Try it,

 [[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]; 
+8
source

You must use the barTintColor property to change the background color in the navigation bar, as well as the background color in the status bar.

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

Source: https://habr.com/ru/post/983703/


All Articles