2011-12-05 71 views
4

我已經使用Ray Wenderlich和iOS Blog中的方法自定義了選項卡欄,但是因爲我使用的是淺色作爲背景,所以文本標籤看起來很糟糕,我想將它們更改爲與我的樣式相匹配。這是可能的和如何?如何自定義UITabBar文本標籤?

如果它不可能或如果它太複雜我想問如何將圖標圖像向下移動,以便它在標籤欄中居中?這樣我可以在.png文件上「寫」標籤。

我打算爲iOS5 +開發這​​個應用程序,所以不用擔心它與iOS4兼容(儘管如果任何人發現這樣做的簡單方法,我會非常感激)。

這裏的what I got到目前爲止,這裏的what I want

的代碼爲我tabBarBackground:

UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; 
[[UITabBar appearance] setBackgroundImage:tabBarBackground]; 

[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"selection-tab.png"]]; 

而對於圖標:

//Custom TabBar Items 
UIImage *selectedImage = [UIImage imageNamed:@"home-icon-selected.png"]; 
UIImage *unselectedImage = [UIImage imageNamed:@"home-icon.png"]; 

UITabBar *tabBar = rootTabBarController.tabBar; 
//Icons for the 1st Tab 
UITabBarItem *item1 = [tabBar.items objectAtIndex:0]; 
[item1 setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage]; 

回答

-1

使用此定製UITabBarItem文本:

[[UITabBarItem appearance] setTitleTextAttributes: aNSDictionaryOfTextAttributes]; 

有類似的答案here所示的屬性的字典。