iOS 7中的UITabBar色调

0xS*_*ina 13 iphone objective-c uikit ios

选择和取消选择选项卡时,如何指定图像的色调?

我试过这个,但它不起作用:

[[UITabBar appearance] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];
Run Code Online (Sandbox Code Playgroud)

这使得所选图像色调为红色(不是绿色)和未选择的色调灰色(不是红色).

Jos*_*own 25

您可以为选定和未选定的标签栏按钮设置色调颜色,如下所示:

[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor greenColor]];
Run Code Online (Sandbox Code Playgroud)

第一行设置未选择的颜色 - 在此示例中为红色 - 通过设置UIView的tintColor,当它包含在标签栏中时.请注意,这仅设置未选择图像的色调 - 它不会更改其下方文本的颜色.

第二行将标签栏的所选图像色调颜色设置为绿色.

  • 在iOS 8中,至少使用上面的代码,未选中的图像最初显示为红色.但是,标签不会,并且一旦选择更改,未选择的颜色将恢复为其默认值. (8认同)
  • 对我来说,在我选择标签然后取消选择它后,它会变回灰色......?!?奇怪的事情......除了那些外观代理的事情我什么都不做...... (3认同)

G33*_*z0r 0

您使用图像的模板版本吗?

不要使用 设置图像[UIImage imageNamed: @"MyImage"],而是使用 设置图像[[UIImage imageNamed: @"MyImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysTemplate]

此设置以及您的代码应该可以解决此问题。