Search code examples
iosuilabeluifontuiappearance

Styling UILabel using UIAppearance proxy


I have a number of UILabel elements in my app and I'm looking for an easy way to style them using the UIAppearance Proxy object. My current approach is to create different subclasses of UILabel equipped with an UI_APPEARANCE_SELECTOR decorator in order to be accessible though [UILabelSubclass appearance] calls. You can find the sources I'm using as reference here and here. The problem is that I don't want to set the font size but only the font family relying on the size defined in the Storyboard.

How can I set this in the subclass?


Solution

  • I think you can try in your subclass something like:

    UIFont *newFont = [UIFont fontWithName:@"YourFontName" size:self.font.pointSize];
    self.font = newFont