8

I want to use UITabBar but without images. I want the text to occupy full control space. i tried setting image to nil, but text is small and aligned to bottom of tabbaritem.

ArnonZ
  • 3,822
  • 4
  • 32
  • 42
Osama F Elias
  • 1,544
  • 1
  • 11
  • 10

4 Answers4

20

This function changes the font of all UITabBarItems:

[[UITabBarItem appearance] setTitleTextAttributes: aNSDictionaryOfTextAttributes];

you can specify the font type and size with a dictionary of attributes similar to those found in this answer here. And then negatively offset the vertical position of the text with this:

[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -18.0)];
Community
  • 1
  • 1
Jeremy
  • 1,029
  • 10
  • 18
  • @meadlai could you please downvote the answers claiming it is not possible to try and current-ize this question? thanks – Jeremy Apr 02 '14 at 06:52
  • 1
    I had to set the title text attributes for a specific control state. In Swift, this would be, for example: `UITabBarItem.appearance().setTitleTextAttributes([...], forState: UIControlState.Normal)` – Ryan H. Dec 29 '15 at 23:46
1

Copy this to your didFinishLaunchingWithOptions.

NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:17.0], NSFontAttributeName, nil];
[[UITabBarItem appearance] setTitleTextAttributes:attributes forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0.0, -13.0)];
ABCD
  • 7,914
  • 9
  • 54
  • 90
0

While I'm not sure you can use a UITabBar that way, an alternative would be to use a UIToolbar and have "Custom" UIBarButtonItems with the style set to "Plain". That would give you a bar without images and have the text occupy the full control space.

Eric
  • 3,865
  • 4
  • 32
  • 44
-4

Even I googled alot for the same, still I am not able to do that

It's the default,that text comes @ bottom in Tabbar...

But there is an alternative,as you need to create the whole tabitem to be as text

just use the image with the Text written on it.

It's Done !!!

Hope this might help me

Ajay Sharma
  • 4,509
  • 3
  • 32
  • 59
  • This answer is out of date, it is possible. and easy, see my answer – Jeremy Jan 27 '14 at 23:44
  • @meadlai it is right below this one, the function is: [[UITabBarItem appearance] setTitleTextAttributes: aNSDictionaryOfTextAttributes]; – Jeremy Apr 02 '14 at 06:33