adit
adit

Reputation: 33644

UINavigationBar appearance override in iOS 5

I have had the following code:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbarBackBlack.png"] forBarMetrics:UIBarMetricsDefault];
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbarBackBlack.png"] forBarMetrics:UIBarMetricsLandscapePhone];
    [[UINavigationBar appearance] setTintColor:[UIColor colorWithWhite:0.72 alpha:1.0]];

But now I want to have one place in my app where I want the navbar to be a different color than this universal color I've set throughout the app. How can I change this for this particular settings only. Is it possible?

Upvotes: 5

Views: 3173

Answers (2)

bryanmac
bryanmac

Reputation: 39296

You can call setBackgroundImage on the instance of the navigation bar as well.

See this related post:

Custom UITabBar background image not working in iOS 5 and later

You should also condition it on whether it responds to that selector:

if ([navBar respondsToSelector:@selector(setBackgroundImage:)])
{
    [navBar setBackgroundImage:[UIImage imageNamed:@"tabbar_brn.jpg"]];
}
else
{
    // ios 4 code here
}

Upvotes: 5

user187676
user187676

Reputation:

Just use the appearance methods directly on the navigation bar instance instead on the appearance proxy object.

[navBarInstance setBackgroundImage: ... ];

Upvotes: 0

Related Questions