Is it possible to change the font size of tabs?
for(UIViewController *tab in self.tabBarController.viewControllers)
{
[tab.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"Helvetica" size:20.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];
}
IN Swift 4
override func viewDidLoad() {
super.viewDidLoad()
let appearance = UITabBarItem.appearance()
let attributes: [NSAttributedString.Key: AnyObject] = [NSAttributedString.Key(rawValue: NSAttributedString.Key.font.rawValue):UIFont(name: "American Typewriter", size: 12)!, NSAttributedString.Key(rawValue: NSAttributedString.Key.foregroundColor.rawValue): UIColor.orange]
appearance.setTitleTextAttributes(attributes, for: .normal)
}
[leaving this here for my own reference, just a riff off the other working answers. For mem it's a fix for iOS 7, which is beyond the question by a bit...]
@implementation UITabBarController (Util)
- (void) fixForIos7 {
if (!IS_IOS7)
return;
UIFont *tabBarFont = [UIFont systemFontOfSize:12];
NSDictionary *titleTextAttributes = [NSDictionary dictionaryWithObjectsAndKeys:
tabBarFont, UITextAttributeFont, nil];
for(UIViewController *tab in self.viewControllers) {
[tab.tabBarItem setTitleTextAttributes:titleTextAttributes forState:UIControlStateNormal];
}
}
@end
the missing method is
#define IS_IOS7 ( UIDevice.currentDevice.systemVersion.floatValue > 6.9 )
I recommend a better way:
[yourTabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
[NSValue valueWithUIOffset:UIOffsetMake(0,0)], UITextAttributeTextShadowOffset,
[UIFont fontWithName:@"Helvetica" size:18.0], UITextAttributeFont, nil]
forState:UIControlStateNormal];