简体   繁体   English

标签栏项目色调颜色

[英]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?有什么办法可以改变未选中的标签栏项目的颜色吗?

To do this:: follow a simple approach..要做到这一点::遵循一个简单的方法..

  1. Change tintColor as you want根据需要更改 tintColor

  2. Add a new set of images for unselected items and render them in original mode.为未选择的项目添加一组新图像并以原始模式渲染它们。

For more info, read through this link有关更多信息,请阅读此链接

要为应用程序全局设置色调颜色,您需要在应用程序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()因此在您的自定义TabBarViewControllerviewDidLoad()编写此代码

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM