16

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?

Electric Coffee
  • 11,733
  • 9
  • 70
  • 131
Manu
  • 4,730
  • 2
  • 20
  • 45
  • 1
    Trust me none of the user reads the text, I prefer rather spending time on a really good descriptive icon – TeaCupApp Jun 27 '12 at 07:30
  • yes. i want it through programatically – Manu Jun 27 '12 at 07:31
  • can you explain your question? when do you want to change the name of you tabbar item? is there any action that will invoke a method to change the name of that tab bar? and also what have you tried? – janusfidel Jun 27 '12 at 07:32
  • like when i run the app, all the tab bar items will come rite ? at that time all my images with titles should come.. – Manu Jun 27 '12 at 07:35
  • 1
    @doNotCheckMyBlog - I strongly disagree. Icons are useful *once a reader knows what the choice means*, because they are easier to see at a glance. The *FIRST* time a reader sees choices, text is clearer. In my experience, most icons could mean any of a number of possible things, which the text clarifies. Also consider that there are a wide range of users: some are like you and prefer icons, others are like me: I would prefer to ALWAYS have (a tiny, short) text with EVERY icon, except for widely standardized icons. – ToolmakerSteve Dec 21 '16 at 21:42

7 Answers7

12
[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]];
user1478583
  • 342
  • 2
  • 7
  • 1
    it's not coming.. it's showing warning and terminating from there – Manu Jun 27 '12 at 08:44
  • 1
    Why is this upvoted 7 times when there's no such method for UITabBarItem? – devmiles.com Mar 03 '14 at 15:15
  • 3
    For anyone still having issues with this: the method as typed above is incorrect. You need to add the `forState:` parameter after `setTitleTextAttributes:`. It will then compile without warnings and work as expected. – element119 Jul 23 '14 at 17:53
2

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)
Ankit Kumar Gupta
  • 3,994
  • 4
  • 31
  • 54
0

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

Srikar Appalaraju
  • 71,928
  • 54
  • 216
  • 264
0

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.

0

Not possible ,create custome tab bar subclassing UITabbar

0

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];
gabbler
  • 13,626
  • 4
  • 32
  • 44
-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];
Bis Cuit
  • 1
  • 1