We have extended UILabel to be able to apply standard fonts and colors for all uses of a given label type in our apps. Eg.
@interface UILabelHeadingBold : UILabel
@end
In our AppDelegate, we apply fonts and colors like this
[[UILabelHeadingBold appearance] setTextColor:<some color>];
[[UILabelHeadingBold appearance] setFont:<some font>];
When adding a UILabel in our XIB's, we can now select the class to be of type UILabelHeadingBold, and it works as expected. The label is shown with the correct font and color, as specified in our AppDelegate.
However, if we create a label programmatically, eg.
UILabelHeadingBold *headingLabel = [[UILabelHeadingBold alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
[self.mainView addSubview:headingLabel];
the UILabel does not get the expected font/color applied. We have to manually apply these attributes.
Is there a way to make UIAppearance take effect on programatically created UI elements, or does it only work when used within XIB's?