Iam trying to set different UINavigationBar color for different UIViewController in project.Till now i tried following code in ViewdidAppear methode of each UIViewController class and its not working still the color of navigationbar is not changing.
UIImage *navBackgroundImage = [UIImage imageNamed:@"redbar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
Please help me
Implement in previews controller to make navigation bar clear color:
Set custom view in the same frame of navigation bar.
Swift:
Global:
For each UIViewController:
Swift 2.2
Try
Or, on iOS 6,
If you have a navigation controller as rootViewController, get it with:
And then set the color:
And if you want to change the color in each viewcontroller, just put the code in each
viewWillAppear
methodIf you don't want to override the
viewWillAppear
in every viewcontroller, you can create a super viewcontroller for your project. But if it's too late, you can also create a customUINavigationController
and simply override push/pop methods like:Do this for the four methods:
Or at least for the methods you use. And then override
viewWillAppear
in your viewControllers which need another bar color.Using a UINavigationController as your root view, you have to use the following method on the ViewWillAppear method :
It will change your current
UIViewController
navigationbar color :)It seems that you want to set color in storyboard, not in code.
and then, open the attribute inspect,
try different bar tint or change its back image will work.