Skip to content

Changing iOS Font on All Widgets (UILabel, UIButton, etc.)

Screen Shot 2014-01-09 at 2.39.56 PMSometimes it’s necessary to change the font on an app and you don’t want to go into Interface Builder and manually change them all. Ug.

So you can recursively call a method to change the font on all subviews that respond to the setFont: method.

+(void)changeFontOnSubviews:(UIView*)view font:(UIFont*)font color:(UIColor*)color;
    // 1. Set font on this control
    if ([view respondsToSelector:@selector(setFont:)])
        [view performSelector:@selector(setFont:) withObject:font];

    // 2. Set the text color (if color is passed in)
    if (color && [view respondsToSelector:@selector(setTextColor:)])
        [view performSelector:@selector(setTextColor:) withObject:color];

    // 3. Variation: UIButton title color
    if (color && [view isKindOfClass:[UIButton class]])
        [(UIButton*)view setTitleColor:color forState:UIControlStateNormal];

    // 4. Other vaiations?

    // 5. Do the same for subviews
    for (UIView *v in view.subviews)
        [MBConstants changeFontOnSubviews:v font:font color:color];
  1. Check that it responds to the selector and call it. Use ‘performSelector:’ b/c UIView doesn’t respond to setFont: so this avoids warnings.
  2. Set the color (if one is passed in).
  3. UIButtons ‘font’ color method is based on title
  4. There may be other controls you may have to handle differently.
  5. Do the same on all subviews to cover them all.