UIAppearance Protocol Reference
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 5.0 and later. |
| Declared in | UIAppearance.h |
Overview
You use the UIAppearance protocol to get the appearance proxy for a class. You customize the appearance of instances of a class by sending appearance modification messages to the class’s appearance proxy.
There are two ways to customize appearance for objects: for all instances, and for instances contained within an instance of a container class.
To customize the appearance of all instances of a class, you use
appearanceto get the appearance proxy for the class. For example, to modify the tint color for all instances ofUINavigationBar:[[UINavigationBar appearance] setTintColor:myColor];
To customize the appearances for instances of a class when contained within an instance of a container class, or instances in a hierarchy, you use
appearanceWhenContainedIn:to get the appearance proxy for the class:[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setTintColor:myNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], [UIPopoverController class], nil]
setTintColor:myPopoverNavBarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil]
setTintColor:myToolbarColor];
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], [UIPopoverController class], nil]
setTintColor:myPopoverToolbarColor];
In any given view hierarchy, the outermost appearance proxy wins. Specificity (depth of the chain) is the tie-breaker. In other words, the containment statement in appearanceWhenContainedIn: is treated as a partial ordering. Given a concrete ordering (actual subview hierarchy), UIKit selects the partial ordering that is the first unique match when reading the actual hierarchy from the window down.
To support appearance customization, a class must conform to the UIAppearanceContainer protocol and relevant accessor methods must be marked with UI_APPEARANCE_SELECTOR.
Class Methods
appearance
Returns the appearance proxy for the receiver. (required)
Return Value
The appearance proxy for the receiver.
Availability
- Available in iOS 5.0 and later.
Declared In
UIAppearance.happearanceWhenContainedIn:
Returns the appearance proxy for the receiver in a given containment hierarchy. (required)
Parameters
- ContainerClass,
A nil-terminated list of appearance container classes.
Return Value
The appearance proxy for the receiver in a given containment hierarchy.
Discussion
This method throws an exception for any item in the var-args list that is not a Class object that conforms to the UIAppearanceContainer protocol.
Availability
- Available in iOS 5.0 and later.
Declared In
UIAppearance.h© 2011 Apple Inc. All Rights Reserved. (Last updated: 2011-10-12)