2016-11-17 64 views
1

我正在研究UITabBar應用程序。UITabBar所選項目色調

我想更改選定項目顏色與

[[UITabBar appearance] setTintColor:[UIColor redColor]] 

這工作,直到我想設置的TabBar的背景顏色與

[[UITabBar appearance] setBarTintColor:[UIColor blueColor]] 

那麼酒吧是藍色的,但高亮項目是灰色的。

[[UITabBar appearance] setBackgroundColor:[UIColor blueColor]] 

沒有效果。 任何想法? 非常感謝!

+2

代替使用顏色,你可以嘗試使用圖像背景。 –

+0

謝謝 - 與另一個應用程序的圖像背景。但我現在製作了兩種顏色的圖標:) – Steeve

回答

0

您發佈的代碼似乎正在工作。你也可以用圖像來做。試試這個:

[tabBarItem1 setImage:[[UIImage imageNamed:@"home.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 
[tabBarItem1 setSelectedImage:[[UIImage imageNamed:@"home_selected.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]]; 

// Change the tab bar background 
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"]; 
[[UITabBar appearance] setBackgroundImage:tabBarBackground]; 
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:@"tabbar_selected.png"]]; 
+0

謝謝,這就是我現在所做的。我使用UIColor設置背景,但選擇了和未選擇的圖標 – Steeve

2

試試這個代碼

//Set greenColor for normal State 
[UITabBarItem.appearance setTitleTextAttributes:@{ 
     UITextAttributeTextColor : [UIColor greenColor] } forState:UIControlStateNormal]; 
//Set purpleColor for normal State 


[UITabBarItem.appearance setTitleTextAttributes:@{ 
     UITextAttributeTextColor : [UIColor purpleColor] }  forState:UIControlStateSelected]; 

希望這有助於。