Changing iOS Font on All Widgets (UILabel, UIButton, etc.)
Sometimes 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
+(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]; } |
Check that it responds to the selector and call Read more about Changing iOS Font on All Widgets (UILabel, UIButton, etc.)[…]