UIAppearance Protocol Reference

ios5增加的两个统一定制控件样式的函数,具有全局的效果,一劳永逸。用法很简单,文档如下:

UIAppearance Protocol Reference

Conforms to
NSObject
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 appearance to 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 useappearanceWhenContainedIn: 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 inappearanceWhenContainedIn: 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.

你可能感兴趣的:(UIAppearance Protocol Reference)