2012-04-17 88 views
5

在网上搜索如何调整UITabBarItem标题位置的位置时,我跑过了this类似的帖子,仍然想知道如何做到这一点。UITabBarItem标题位置

甚至可以从下往上调整标题位置吗? (例如5px)我需要这个,因为我有自定义图像,现在标题的位置并不完美。

回答

1

为什么你不只是为你的视图控制器有一个空的标题属性,并将标题添加到您的自定义图像的标签?

你可以这样做(在安装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]; 

其中tabIconSelected.pngtabIconNotSelected.png都包含选项卡的标题文字。

我写了一篇简短的文章"Add some colour to your UITabBar icons",它解释了如何使用带有制表符的自定义图像。

希望这会有所帮助。

+1

怎么样的定位? – Claus 2012-09-26 15:16:33

12

如果你想向上移动简单地设置垂直偏移到负值

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

您没有使用代理服务器,因为它是在这里完成UITabBarItem title in centre of title, not at bottom。你可以每个项目限定偏移。

7

斯威夫特版为懒惰的:)

UITabBarItem.appearance().titlePositionAdjustment = UIOffsetMake(0.0, -4.0) 
1

在Objective-C的全球调整:

[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -4)];