Brian
Brian

Reputation: 79

iOS 5 [UINavigationBar appearance] setBackgroundImage does not do work

I created a new test iOS5 project in Xcode 4.2 Build 4D199 and tried to set the appearance of the UINavigationBar as described above, but nothing happens.

The code I tried in the viewDidLoad:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"navbar-iphone.png"] forBarMetrics:UIBarMetricsDefault];

The only way I can get it to work is to set the appearance on the instance of the UINavigationBar. Like:

[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navbar-iphone.png"] forBarMetrics:UIBarMetricsDefault];

What is going on? Has anyone else had this issue?

Upvotes: 5

Views: 7283

Answers (3)

matt
matt

Reputation: 535149

viewDidLoad is the wrong place to be messing with the appearance proxy of a navigation controller's navigation bar. Do this sort of thing before the navigation controller is even created. In your app delegate's applicationDidFinishLaunching is a good place.

Upvotes: 18

James
James

Reputation: 6499

You will need to provide forBarMetrics: for this to work.

Upvotes: 1

thedanielhanke
thedanielhanke

Reputation: 738

Did you double-check if that Imagefile does exist?

Upvotes: 1

Related Questions