簡體   English   中英

UITabBar選擇項目色調顏色

[英]UITabBar Selected Item Tint Color

我正在研究UITabBar-Application。

我想用更改所選的項目顏色

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

這有效,直到我想設置TabBar的背景顏色

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

然后條形圖為藍色,但突出顯示的項目為灰色。

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

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

試試這個代碼

//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];

希望這可以幫助。

您發布的代碼似乎正在運行。 你也可以用圖像來做。 嘗試這個:

[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"]];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM