[英]Tab bar item tint color
In iOS 7, I been developing an app that uses the UITabBarController and I noticed that the tab bar items stay gray even tho I change the tint color of the tab bar.在 iOS 7 中,我一直在开发一个使用 UITabBarController 的应用程序,我注意到即使我更改了标签栏的色调,标签栏项目仍然保持灰色。 Is there any way to change the color of non-selected tab bar items?
有什么办法可以改变未选中的标签栏项目的颜色吗?
要为应用程序全局设置色调颜色,您需要在应用程序delegate didFinishLaunchingWithOptions: method
添加以下代码:
[[UITabBar appearance] setTintColor:[UIColor colorWithRed:13.0/255.0 green:116.0/255.0 blue:128.0/255.0 alpha:1.0]];
@shreena app的Swift 3委托全局标签栏色调设置
UITabBar.appearance().tintColor = UIColor(red: CGFloat(13.0 / 255.0), green: CGFloat(116.0 / 255.0), blue: CGFloat(128.0 / 255.0), alpha: CGFloat(1.0))
Changing the tabBar.tintColor
property is the right way to do it, however to make it work we need to tell iOS to ignore color properties of the UIImage
in TabBarItem
.更改
tabBar.tintColor
属性是正确的方法,但是要使其工作,我们需要告诉 iOS 忽略TabBarItem
UIImage
颜色属性。 Hence write this code in your custom TabBarViewController
's viewDidLoad()
因此在您的自定义
TabBarViewController
的viewDidLoad()
编写此代码
for item in self.tabBar.items ?? [] {
item.selectedImage = item.selectedImage?.withRenderingMode(.alwaysTemplate)
item.image = item.image?.withRenderingMode(.alwaysTemplate)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.