How do I apply UIAppearance Proxy properties to UILabel?

Joshua J. McKinnon picture Joshua J. McKinnon · Aug 7, 2012 · Viewed 12.8k times · Source

I have been getting unreliable results while trying to apply UIAppearance proxy styles to the UILabel class proxy. For example, the following works as I would expect:

[[UILabel appearance] setFont:[UIFont fontWithName:SOME_FONT size:SOME_SIZE]];
[[UILabel appearance] setShadowColor:[UIColor blackColor]];

Setting the textColor doesn't work, however, this:

[[UILabel appearance] setColor:[UIColor greenColor]];

does work. Kind of. It's somewhat unreliable and causes any instance-specific calls to setTextColor: to be ignored.

What is the correct way to apply UIAppearance styles to a UILabel?

Answer

Joshua J. McKinnon picture Joshua J. McKinnon · Aug 7, 2012

OK, it turns out that you cannot style any UILabel properties using the UIAppearance proxy.

While the UILabel class conforms to the UIAppearanceContainer protocol, a check of UILabel.h shows that none of its properties are marked with UI_APPEARANCE_SELECTOR, the prerequisite for the use of UIAppearance.

Bugger.