UITabBar 色调颜色不适用于图像

UITabBar tint color not working on images

我使用 Interface Buider 进行了 UITabBar 设置,只有在我未设置全局应用色调颜色时图像突出显示才能正常工作:

当我使用

设置我的应用程序的全局色调时
[[UIView appearance] setTintColor:[TAStyleKit tintColor]];

然后所有选项卡图像都显示为选中状态。

只有当我单击选项卡并再次返回时,它们才具有正确的颜色。请注意此处为灰色的 "Weapons" 选项卡:

我做错了什么?

编辑:不管我之前写的是什么,看起来你只需要更改以下...

[[UIView appearance] setTintColor:[TAStyleKit tintColor]];

到...

[[UITabBar appearance] setTintColor:[TAStyleKit tintColor]];

请注意,您试图更改 UIView 而非 UITabBar 的外观运行ce。我 运行 在一个项目中使用它,它成功了。

Swift 4.0

UITabBar.appearance().tintColor = UIColor.redTAStyleKit.tintColor

当您不能或不想删除基本 UIView.tintColor 代码时,这可能是一个更好的方法。只需将标签栏内 UIViews 上的 tintColor 设置为默认灰色即可。

let view = UIView.appearance()
view.tintColor = UIColor.redColor()

let viewsInTabBar = UIView.appearanceWhenContainedInInstancesOfClasses([UITabBar.self])
viewsInTabBar.tintColor = UIColor(white: 144.0 / 255.0, alpha: 1) // default gray for inactive items

let tabBar = UITabBar.appearance()
tabBar.tintColor = UIColor.redColor() // actual highlight color

不幸的是,苹果不使用其标准灰度值之一...

也可以直接从 Storyboard 中设置[XCode10.1] 通过为 UITabBar 设置 Image Tint