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我希望未选择的颜色是白色,选择的颜色是红色。iOS 9中不推荐使用selectedImageTintColor属性,我想知道如何才能更改未选中的图像颜色?此外,通过将tabbar keypath的颜色属性更改为红色,我还可以将所选图像的色调颜色更改为故事板中的红色。我想知道是否有一种方法可以改变故事板中未选中和选中的颜色?
发布于 2016-06-02 20:29:57
确保原始图像显示为白色。
let tabBarImage = UIImage(named: "icon-tab-name")
let tabBarItem = UITabBarItem(title: "Title", image: tabBarImage?.imageWithRenderingMode(.AlwaysOriginal), selectedImage: tabBarImage)然后就有
UITabBar.appearance().tintColor = UIColor.redColor()这样,您将拥有一个白色未选定状态和一个红色选定状态。
发布于 2015-11-24 05:31:25
我在viewDidLoad方法中使用了这段简单的代码:
self.tabBar.tintColor = UIColor.whiteColor()发布于 2018-09-16 01:54:08
如果你想在iOS10中改变所有这些,可以在appDelegate中这样做。这会将所有未选中的更改为黑色。
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
UITabBar.appearance().unselectedItemTintColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 1)
return true
}https://stackoverflow.com/questions/33877281
复制相似问题