我在Interface Builder中设置了一个UITabBar
,只有当我不设置全局应用程序色调时,图像高亮才能正常工作:
当我使用以下代码设置应用程序的全局色调时:
[[UIView appearance] setTintColor:[TAStyleKit tintColor]];
然后所有的选项卡图像都会显示为选中状态。
只有当我点击选项卡并再次返回时,它们才具有正确的颜色。请注意这里是灰色的“武器”选项卡:
我错在哪里了?
我在Interface Builder中设置了一个UITabBar
,只有当我不设置全局应用程序色调时,图像高亮才能正常工作:
当我使用以下代码设置应用程序的全局色调时:
[[UIView appearance] setTintColor:[TAStyleKit tintColor]];
然后所有的选项卡图像都会显示为选中状态。
只有当我点击选项卡并再次返回时,它们才具有正确的颜色。请注意这里是灰色的“武器”选项卡:
我错在哪里了?
编辑:不用管我之前写的内容了,看起来你只需要更改下面的内容...
[[UIView appearance] setTintColor:[TAStyleKit tintColor]];
To...
[[UITabBar appearance] setTintColor:[TAStyleKit tintColor]];
请注意,您试图更改UIView的外观而不是UITabBar的外观。 我在一个项目中运行了这个代码并且奏效。
Swift 4.0
UITabBar.appearance().tintColor = UIColor.red
或者 TAStyleKit.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
很遗憾,苹果不使用其标准灰度值之一...
TabView(
...
)
.tint(Color.red)
.accentColor
。
UIView
上的色调,因为我希望所有的 UI 元素都具有这种色调,而不是默认的蓝色。 - Jan