On the tech talk 2011 I saw a speech about the new UIAppearance
protocol. There is not a lot of documentation out there yet. I will shortly summarize what I re
a: The following line
[[UITableView appearance] setBackgroundColor:[UIColor blueColor]];
Will make every table view blue! Just tested on iOS 5 simulator.
b: The UIAppearance should work on every property on a UIView
. All the subclasses of UIView
conforms to UIAppearance Protocol
c: I think that the most of will create an class and or method that will customize the appearance and will call it in:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Something like: [ApplicationAppearance setApplicationSchemaTo:ASchemaBlue];
Edit:
For example, UIBarButtonItem defines these methods:
@property(nonatomic,retain) UIColor *tintColor UI_APPEARANCE_SELECTOR;
From UIAppearanceContainer Protocol Reference
And in the UIBarButtonItem Class Reference the tintColor is defined
@property(nonatomic, retain) UIColor *tintColor
But in the UIBarButtonItem.h is defined:
@property(nonatomic,retain) UIColor *tintColor __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0) UI_APPEARANCE_SELECTOR;
I think that the docs are not up to date.
a) How do I know which instances of a class work with the appearance property? For e.g. since UITableView conforms to the UIAppearance protocol I was thinking I could do something like
You look in the header of the class (and the headers of all the superclasses). Any method that has UI_APPEARANCE_SELECTOR
next to it is supported for use with the UIAppearance
proxy.
[[UITableView appearance] setBackgroundColor:mytableViewColor];
The backgroundColor
property is not decorated with UI_APPEARANCE_SELECTOR
in UIView.h
. Thus it is not technically supported for use with the appearance proxy. It will probably work, but (given the lack of method decoration) isn't guaranteed to.
From the UIAppearance Protocol Reference
:
To support appearance customization, a class must conform to the
UIAppearanceContainer
protocol and relevant accessor methods must be marked withUI_APPEARANCE_SELECTOR
.
(note "and relevant accessor methods must be marked..." [emphasis added])
b) Is there a list of all properties that are manipulatable with the appearance property?
Is there a single page showing every setter that works with the appearance proxy? I don't know of one, nor is there a way to build the list at runtime.
c) At what point is the appearance customization being called? I was hoping to make changes threw the appearance property at runtime, but unfortunately the changes aren't taking place.
You can use the appearance proxy at any point during execution. The changes won't be applied to the affected views until the next time those views have their -layoutSubviews
method invoked.
UIAppearance
is documented within the headers of each class. Look within there for methods marked UI_APPEARANCE_SELECTOR
at the very end. Those are the methods you can call through the appearance proxy. I'm not aware of a list outside of the headers.
The appearance customization is called immediately after passing through the proxy, as well as whenever a new object is constructed. But this will only work for methods marked with that UI_APPEARANCE_SELECTOR