I am doing an app based on tabbarController. I have a 3 tabbar items.
My question is: How can I change the font-style for the title on the tab-bar item?
I am doing an app based on tabbarController. I have a 3 tabbar items.
My question is: How can I change the font-style for the title on the tab-bar item?
[self.tabBarItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont,
[UIColor blackColor], UITextAttributeTextColor,
[UIColor grayColor], UITextAttributeTextShadowColor,
[NSValue valueWithUIOffset:UIOffsetMake(0.0f, 1.0f)], UITextAttributeTextShadowOffset,
nil]];
This will change ur UITabBarItem fonts once and for all throughout the app
For Swift use this in AppDelegate's didFinishLaunching:
Swift 3:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.blue,NSFontAttributeName: UIFont(name: "Montserrat", size: 11)!], for: .normal)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.red,NSFontAttributeName: UIFont(name: "Montserrat", size: 11)!], for: .selected)
Sorry, I dont think there's a way to do this. If you're desperate, you'll need to write your own tab bar.
Sadly, this isn't possible currently on iOS unless you build your own custom tab bar, which isn't very difficult with storyboarding on iOS5.
If you see this error: 'UITextAttributeTextShadowOffset' is deprecated: first deprecated in iOS 7.0 - Use NSShadowAttributeName with an NSShadow instance as the value.
,try this.
NSShadow *shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor grayColor];
shadow.shadowOffset = CGSizeMake(0.0, 0.5);
NSDictionary *attribute = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont fontWithName:@"AmericanTypewriter" size:10.0f], NSFontAttributeName,
[UIColor blackColor], NSForegroundColorAttributeName,
shadow,NSShadowAttributeName,nil];
[[UITabBarItem appearance] setTitleTextAttributes:attribute forState:UIControlStateNormal];
Try this.
[[UITabBarItem appearanceWhenContainedIn:[UITabBar class], nil]
setTitleTextAttributes:@{NSForegroundColorAttributeName:
[UIColor colorWithRed:0/255.0f green:130/255.0f blue:202/255.0f alpha:1.0],
NSFontAttributeName:[UIFont fontWithName:@"Signika-Semibold" size:20.0]
}
forState:UIControlStateNormal];