我已经尝试了几乎最大的解决方案,它没有帮助,选定的状态颜色正在应用,但对于正常状态,它不适用。这个问题我只在iOS13.2中遇到过。
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: tabFont,
NSAttributedString.Key.foregroundColor: UIColor.yellow],
for: .selected)
tabBarItem.setTitleTextAttributes([NSAttributedString.Key.font: tabFont,
NSAttributedString.Key.foregroundColor: UIColor.white],
for: UIControl.State.normal)我已经在plist中禁用了暗模式。它始终显示为灰色。

发布于 2019-11-20 08:44:17
现在还不清楚问题是什么。这是iOS 13中的一个错误,或者至少是一个严重的行为改变。
要查看这一点,只需从选项卡式应用程序模板创建新项目,并在第一个视图控制器的初始化器中应用您的代码:
class FirstViewController: UIViewController {
required init?(coder: NSCoder) {
super.init(coder:coder)
let tabFont = UIFont(name: "Georgia", size: 14)!
tabBarItem.setTitleTextAttributes([.font: tabFont,
.foregroundColor: UIColor.yellow],
for: .selected)
tabBarItem.setTitleTextAttributes([.font: tabFont,
.foregroundColor: UIColor.white],
for: UIControl.State.normal)
}
}在iOS 12上,选项卡栏项目文本在选中时为黄色,未选中时为白色。但在iOS 13中,未选中时,栏项目文本为灰色。
我还没有找到一个令人满意的方法来解决这个问题。根据评论中的建议,您可以这样说:
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.tabBarController?.tabBar.unselectedItemTintColor = .white
}但是这个画笔太宽了,因为它会给所有的选项卡栏项目着色,也会给图像着色。
您可以尝试使用新的UITabBarItemAppearance类,但这会产生其他不受欢迎的副作用。
因此,除了提交错误报告之外,您也无能为力。
https://stackoverflow.com/questions/58748592
复制相似问题