1
我想为处于未选中状态的UITabBarItem
的标题文本和图像设置不同的颜色。如何在UITabBarItem上设置不同的未选中图像和文本颜色
对于选定的状态,我可以做到这一点,像这样:
[[UITabBar appearance] setTintColor:[UIColor purpleColor]]; // image color
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor orangeColor] } forState:UIControlStateSelected]; // text color
对于未选择状态,我试图如下:
[[UITabBar appearance] setUnselectedItemTintColor:[UIColor blueColor]]; // image color
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName: [UIColor redColor] } forState:UIControlStateNormal]; // text color
但由于某些原因,unselectedItemTintColor
设置覆盖任何我尝试设置的titleTextAttributes
- 因此在上面的代码片段中,文本和图片都会显示为蓝色。
我也试过直接更改titleTextAttributes
上我已经创建后UITabBarItem
(而不是使用appearance
),但这又似乎没有任何效果。
如何获得不同的未选颜色?可能吗?
这肯定看起来像一个错误。选项可能是1)仅使用图像,或2)使用自定义视图的标签栏项目,或3)自定义标签栏控制器? – DonMag