2015-11-23 33 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() 

这种方式,您将有一个白色未选择状态和红色选中状态。