I'm using iOS's UIAppearanceProxy to customize the look of my app.
In most of the app, I want the navBar to have one background image. In one specific section of the app, I want the navBar to have a different background image.
Here's what I'm doing in application:didFinishLaunchingWithOptions:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar_bg1"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[DiscoverViewController class], nil] setBackgroundImage:[UIImage imageNamed:@"navbar_bg2"] forBarMetrics:UIBarMetricsDefault];
I would like to keep all my appearance code in one place instead of overriding the navBar in a specific view controller.
Also helpful to know is that my app is structured with a TabBarController, where each tab controls a NavigationController which owns a subclassed ViewController, like DiscoverViewController above.
What am I doing wrong?
As you just stated, the navigation bar is not contained in the DiscoverViewController
in your hierarchy; rather, both are contained in a navigation controller. One way to keep the appearance code centralized is to create an empty subclass of UINavigationController
and instantiate that instead of UINavigationController
in the relevant place (whether that's a nib or storyboard or just programmatically). Then, to style child elements, get their appearance proxy "when contained in" DiscoveryNavigationController
or what have you. I've used this method with good results in the past.