首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在iOS 13.2的情况下,UIBarButtonItem的.normal阶段的TintColor不会更改

在iOS 13.2的情况下,UIBarButtonItem的.normal阶段的TintColor不会更改
EN

Stack Overflow用户
提问于 2019-11-07 20:15:37
回答 1查看 316关注 0票数 2

我已经尝试了几乎最大的解决方案,它没有帮助,选定的状态颜色正在应用,但对于正常状态,它不适用。这个问题我只在iOS13.2中遇到过。

代码语言:javascript
复制
        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中禁用了暗模式。它始终显示为灰色。

EN

回答 1

Stack Overflow用户

发布于 2019-11-20 08:44:17

现在还不清楚问题是什么。这是iOS 13中的一个错误,或者至少是一个严重的行为改变。

要查看这一点,只需从选项卡式应用程序模板创建新项目,并在第一个视图控制器的初始化器中应用您的代码:

代码语言:javascript
复制
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中,未选中时,栏项目文本为灰色。

我还没有找到一个令人满意的方法来解决这个问题。根据评论中的建议,您可以这样说:

代码语言:javascript
复制
override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    self.tabBarController?.tabBar.unselectedItemTintColor = .white
}

但是这个画笔太宽了,因为它会给所有的选项卡栏项目着色,也会给图像着色。

您可以尝试使用新的UITabBarItemAppearance类,但这会产生其他不受欢迎的副作用。

因此,除了提交错误报告之外,您也无能为力。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58748592

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档