在iOS 7中,我正在开发一个使用UITabBarController的应用程序,并且我注意到即使我更改了选项卡栏的色调颜色,选项卡项目仍保持灰色。是否有办法更改非选定选项卡项目的颜色?
要在应用程序全局设置色彩,您需要在应用程序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]];
更改tabBar.tintColor
属性是正确的方法,但为了使其起作用,我们需要告诉iOS忽略TabBarItem
中UIImage
的颜色属性。
因此,请在您自定义的TabBarViewController
的viewDidLoad()
中编写此代码。
for item in self.tabBar.items ?? [] {
item.selectedImage = item.selectedImage?.withRenderingMode(.alwaysTemplate)
item.image = item.image?.withRenderingMode(.alwaysTemplate)
}