![](/img/trans.png)
[英]Customizing icon position and title of UITabBarItem's (iphone sdk)
[英]UITabBarItem title position
在網上搜索如何調整UITabBarItem標題位置的位置時,我跑過這個類似的帖子,仍然想知道如何做到這一點。
甚至可以從下往上調整標題位置嗎? (例如5px)我需要這個,因為我有自定義圖像,現在標題的位置並不完美。
如果要向上移動,只需將垂直偏移設置為負值即可
UITabBarItem* it = [[self.tabController.tabBar items] objectAtIndex:0];
it.titlePositionAdjustment = UIOffsetMake(0.0, -2.0);
您不必使用代理,因為它在標題中心的UITabBarItem標題處完成,而不是在底部 。您可以定義每個項目的偏移量。
Swift版本為懶人:)
UITabBarItem.appearance().titlePositionAdjustment = UIOffsetMake(0.0, -4.0)
為什么不為視圖控制器設置空標題屬性並將標題添加到標簽的自定義圖像?
你可以這樣做(在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.png
和tabIconNotSelected.png
都包含選項卡的標題文本。
我寫了一篇簡短的文章“為你的UITabBar圖標添加一些顏色” ,它解釋了如何使用帶有標簽的自定義圖像。
希望這可以幫助。
目標C的全球調整:
[[UITabBarItem appearance] setTitlePositionAdjustment:UIOffsetMake(0, -4)];
如果您想要更新所有這些:
tabBar.items?.forEach({ $0.titlePositionAdjustment = UIOffset(horizontal: 0.0, vertical: -2.0) })
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.