2015-11-23 72 views
2
override func viewDidLoad() { 
     super.viewDidLoad() 

     // Do any additional setup after loading the view.' 
     UITabBar.appearance().tintColor = UIColor.whiteColor() 
     UITabBar.appearance().selectedImageTintColor = UIColor.redColor() 
    } //method is in TabBarViewController 

我希望未選中的顏色爲白色,所選顏色爲紅色。 selectedImageTintColor屬性在iOS 9中已棄用,我想知道如何才能更改未選中的圖像顏色?此外,通過將tabbar keypath的顏色屬性更改爲紅色,我可以將所選圖像色調更改爲故事板中的紅色。我想知道是否有更改故事板中未選中和選定顏色的方法?更改未選中的UITabBar項目的顏色iOS 9

回答

0

我沒有在viewDidLoad方法這個和平的代碼:

self.tabBar.tintColor = UIColor.whiteColor() 
+0

對不起,我在描述中不清楚。我想要取消選中的白色和選中的紅色。當我將淺色設置爲白色時(與您的代碼或變體一樣),它選中爲紅色,但未選中爲白色, – stumped

+0

我解決了與UIImage imageWithRenderingMode方法相結合的類似問題。就像這樣:'myImage.imageWithRenderingMode(.AlwaysOriginal)' –

1

確保您的原始圖像顯示爲白色。然後你只需告訴TabBarItem呈現未選擇的圖像作爲.AlwaysOriginal和設置就可以了selectedImage像這樣:

let tabBarImage = UIImage(named: "icon-tab-name") 
let tabBarItem = UITabBarItem(title: "Title", image: tabBarImage?.imageWithRenderingMode(.AlwaysOriginal), selectedImage: tabBarImage) 

再有

UITabBar.appearance().tintColor = UIColor.redColor() 

這種方式,您將有一個白色未選擇狀態和紅色選中狀態。