Search code examples
objective-ciosuinavigationbaruiappearance

How to get rid of UIAppearance when not needed?


In my AppDelegate I use UIAppearance to set my own NavigationBar with this code :

[[UINavigationBar appearance] setTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"nav5.png"] forBarMetrics:UIBarMetricsDefault];

But some views of my application don't need it. How can I get rid of it so I may only use IB in concerned views ?


Solution

  • You don't need to use the proxy. Just get the actual navigationBar, which should look different and set the colors directly on it.

    [navigationBarInstance setTintColor:[UIColor blackColor]];
    [navigationBarInstance setBackgroundImage:[UIImage imageNamed:@"nav5.png"] forBarMetrics:UIBarMetricsDefault];
    

    You can also just set both values to nil, where you want the standard styles again. (tested by Ben Clayton).

    [navigationBarInstance setTintColor:nil];
    [navigationBarInstance setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];