iOS8 Swift TabBarController 更改图标颜色
iOS8 Swift TabBarController Change Icon Color
我正在尝试更改 TabBarController 中图标的颜色。
我已经成功更改了文本颜色(就在图标下方),但无法弄清楚如何更改图标颜色。
我已经像这样更改了图标文本颜色:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:.Normal)
我已将其放入我的 AppDelegate.swift (didFinishLaunchingWithOptions)。
现在选中的项目文本是橙色的,未选中的是白色的。
然而,图标仍然是蓝色/深灰色。我该如何更改这些?
未选中:
已选择:
通过 UIAppearance 设置 tintColor
属性。
作为 tBVC 我的 tabBarViewController,我只是这样做:
tBVC.tabBarItem.selectedImage = UIImage(named: "k-lenda(Hi)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
tBVC.tabBarItem.image = UIImage(named: "k-lenda(Lo)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
在属性检查器中,我有条形项的 "Hi" 图像。
希望对您有所帮助!
我正在尝试更改 TabBarController 中图标的颜色。 我已经成功更改了文本颜色(就在图标下方),但无法弄清楚如何更改图标颜色。
我已经像这样更改了图标文本颜色:
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState:.Selected)
UITabBarItem.appearance().setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.whiteColor()], forState:.Normal)
我已将其放入我的 AppDelegate.swift (didFinishLaunchingWithOptions)。 现在选中的项目文本是橙色的,未选中的是白色的。 然而,图标仍然是蓝色/深灰色。我该如何更改这些?
未选中:
已选择:
通过 UIAppearance 设置 tintColor
属性。
作为 tBVC 我的 tabBarViewController,我只是这样做:
tBVC.tabBarItem.selectedImage = UIImage(named: "k-lenda(Hi)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
tBVC.tabBarItem.image = UIImage(named: "k-lenda(Lo)")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
在属性检查器中,我有条形项的 "Hi" 图像。
希望对您有所帮助!