10

On searching the web on how to adjust the position of a UITabBarItem title position i ran over this similar post and still wondering how to do that.

Is it even possible to adjust the title position a bit from the bottom up? (for example 5px) I need this because i have custom images and now the position of the title is not perfect.

Community
  • 1
  • 1
user944351
  • 1,213
  • 2
  • 19
  • 27

5 Answers5

17

If you want to move up simply set vertical offset to negative value

UITabBarItem* it = [[self.tabController.tabBar items] objectAtIndex:0];
it.titlePositionAdjustment = UIOffsetMake(0.0, -2.0);

You don't have to use proxy as it is done here UITabBarItem title in centre of title, not at bottom.You can define offset per item.

Community
  • 1
  • 1
Radek
  • 581
  • 4
  • 12
13

Swift version for the lazy ones :)

UITabBarItem.appearance().titlePositionAdjustment = UIOffsetMake(0.0, -4.0)
ergunkocak
  • 3,334
  • 1
  • 32
  • 31
4

If you want to update all of them:

tabBar.items?.forEach({ $0.titlePositionAdjustment = UIOffset(horizontal: 0.0, vertical: -2.0) })
pierre23
  • 3,846
  • 1
  • 28
  • 28
1

Why don't you just have an empty title property for your view controller and add the title to your custom images for the tab?

You can do this (in iOS 5.0):

UIImage* iconSelected = [UIImage imageNamed:@"tabIconSelected.png"];
UIImage* iconNotSelected = [UIImage imageNamed:@"tabIconNotSelected.png"];
UITabBarItem *updatesListItem = [[UITabBarItem alloc] initWithTitle:@"" image:iconSelected tag:0];
[updatesListItem setFinishedSelectedImage:iconSelected withFinishedUnselectedImage:iconNotSelected];
[navigationController setTabBarItem:updatesListItem];

where tabIconSelected.png and tabIconNotSelected.png both contain the title text for the tab.

I have written a brief article "Add some colour to your UITabBar icons" which explains how to use custom images with tabs.

Hope this helps.

Andy Sinclair
  • 2,143
  • 16
  • 18
1

Global adjustment in objective-C:

[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -4)];
niggeulimann
  • 688
  • 6
  • 15