Manu
Manu

Reputation: 4750

How to change the font size of the tab bar controller item name?

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?

Upvotes: 16

Views: 15012

Answers (7)

Ankit Kumar Gupta
Ankit Kumar Gupta

Reputation: 4042

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)

Upvotes: 2

Bis Cuit
Bis Cuit

Reputation: 1

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];

Upvotes: -1

gabbler
gabbler

Reputation: 13766

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];

Upvotes: 0

user1478583
user1478583

Reputation: 342

[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]];

Upvotes: 12

user1048972
user1048972

Reputation: 19

Not possible ,create custome tab bar subclassing UITabbar

Upvotes: 0

Zachary Christopoulos
Zachary Christopoulos

Reputation: 643

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.

Upvotes: 0

Srikar Appalaraju
Srikar Appalaraju

Reputation: 73688

Sorry, I dont think there's a way to do this. If you're desperate, you'll need to write your own tab bar.

Upvotes: 0

Related Questions