I'm building an app with many view controllers: I have a UITabBarController
which holds 4 UINavigationController
. I want all the nav bars to be my custom color, say blue, which I achieve by doing this in my app delegate:
[[UINavigationBar appearance] setTintColor:[UIColor blueColor]];
But I also have one special view controller which has a map, and for this view controller I want to override the blue navbar set using UIAppearance
to make it the black opaque style. I've tried by calling this inside viewDidLoad
:
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = YES;
But nothing happens. Can this be done or do I have to abandon UIAppearance and set the properties on navigationBar
manually for each view controller?
The way you are doing it is supposed to work, but it doesn't. This does work though:
UINavigationBar.appearance(whenContainedInInstancesOf: [YourOtherVC.self]).tintColor = .black
[[UINavigationBar appearanceWhenContainedIn:[YourOtherVC class], nil] setTintColor:[UIColor blackColor]];
Move your changes to viewWillAppear: instead of viewDidLoad: and it should work.
For that you would do:
id specialNavBarAppearance = [UINavigationBar appearanceWhenContainedIn:[SpecialViewController class], nil];
[specialNavBarAppearance setBarStyle:UIBarStyleBlack];
[specialNavBarAppearance setTranslucent:YES];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With