Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar and new iOS 5+ appearance API - how to supply two background images?

I want to exploit the new iOS 5 appearance API to supply custom background images to all UINavigationBar instances in my app. To do this, it's as simple as this:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"whatever.png"] forBarMetrics:UIBarMetricsDefault];

However, for each instance, I want to provide a different image depending on the value of the translucent property, e.g.

// For UINavigationBar instances where translucent returns YES:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"whatever-translucent.png"] forBarMetrics:UIBarMetricsDefault];

// Otherwise:

[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:@"whatever.png"] forBarMetrics:UIBarMetricsDefault];

Given that the appearance APIs seem to be configured using class methods, is something like this possible?

like image 683
Mark Beaton Avatar asked Oct 13 '11 23:10

Mark Beaton


1 Answers

At the moment, there's no way to do what you're describing - the appearance proxy doesn't know anything about any particular instance at the time you're calling for it.

In practical terms, what you'll probably need to do is figure out how many translucent bars you'd have v. how many non-translucent ones you had. Choose whichever you have more of and use the appearance proxy for that one - for the others, when you go to make it translucent (or ask for full-screen layout), you'll have to set the background image then.

In the meantime, could you file an enhancement request at http://bugreport.apple.com/ for what you're asking? It's not an unreasonable request. Thanks!

like image 191
Chris Parker Avatar answered Sep 19 '22 07:09

Chris Parker