Since iOS 5 as a developer you can finally change the tint/design of some elements without much trouble. Changing the background of your
UINavigationBar just became so much easier.
The classes that support the
UIAppearance protocol have access to an appearance selector. This returns the appearance proxy for the receiver.
It’s on this proxy that you can call selectors like
Here is a list of classes that are supported:
Change the navigation bar background
Here is a quick example how you can easily set the background image of a navigation bar for the whole application.
Add the following line of code to your
application:didFinishLaunchingWithOptions: in your AppDelegate:
This will set the navbar.png image as a background on your navigation bar for all the navigation bars in your application.
Appearance depending on containment
But what if you want your popover to have the default blue
UINavigationBar, but you just changed the appearance for the application. Than you can add this line of code:
UINavigationBar is used inside a
UIPopoverController, then the background image for the navigation bar will be nil, and therefore the default background will be shown.
You can use
UIPopoverController, your custom
UIViewController classes, etc… as the containment classes.
What selectors are available on a class
How to find out which selectors can be accessed by the appearance proxy? Just go to XCode and go to the header file of a class, for example
In this header file you find the methods supported by the proxy by searching for the
UI_APPEARANCE_SELECTOR constant. This is located behind the method definition.
You notice that the
UINavigationBar appearance proxy supports the following selectors:
Sign up for our newsletter
Who’s got the mic?
Architecture & Design
Koen Van Der Auwera
Bob Van Landuyt
Nathan de Witte