Change the color of the NavigationBar (background color)

I keep reading to change the default color in the navigation bar. I just need to update the first method in appdelegate for this

self.window.rootViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 

but it does not seem to work, so I tried to set it also in the viewDidLoad method of the first kind:

 self.parentViewController.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 

That didn't work either. How can i change this?

+6
source share
4 answers

Do not use self.parentViewController , but self :

 self.navigationController.navigationBar.tintColor = [UIColor whiteColor]; 
+6
source

When iphone 5 arrives, we need to install both types of device. Therefore use this

 if([self.navigationController.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)] ) { //iOS 5 new UINavigationBar custom background [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbg_ForiPhone5_Imagename.png"] forBarMetrics: UIBarMetricsDefault]; } else { [self.navigationController.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"navbg_ForOtherIphone_Imagename.png"]] atIndex:0]; } 
+1
source

In iOS7, you can try the following:

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

You can do the following:

I created a new UINavigationController , for example UIDemoNavController , with the result:

 - (void)viewDidLoad{ [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; [super viewDidLoad]; } 

This is the full demo class:

 #import "UIDemoNavController.h" @interface UIDemoNavController() @end @implementation UIDemoNavController - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) {} return self; } - (void)viewDidLoad{ [[UINavigationBar appearance] setBarTintColor:[UIColor redColor]]; [super viewDidLoad]; } - (void)didReceiveMemoryWarning{ [super didReceiveMemoryWarning]; } @end 
+1
source

Try self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
UIViewController class has a navigationController property, which returns the built-in navigation controller regardless of depth, otherwise it returns nil .

0
source

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


All Articles