【问题标题】:TintColor not changing for UIBarButtonItem for .normal stage in case of iOS 13.2在 iOS 13.2 的情况下,.normal 阶段的 UIBarButtonItem 的 TintColor 不会改变
【发布时间】:2020-03-04 00:37:07
【问题描述】:

我尝试了几乎最大的解决方案,但没有帮助,选择的状态颜色正在应用,但对于正常状态,它没有应用。我只在 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 中禁用了暗模式。它始终显示为灰色。

【问题讨论】:

  • 你试过了吗? : self.tabBar.unselectedItemTintColor = .lightGray

标签: swift ios13 swift5 xcode11.2 ios13.2


【解决方案1】:

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

要看到这一点,只需从 Tabbed App 模板创建新项目,然后在第一个视图控制器的初始化程序中应用您的代码:

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 中,bar item 文本在未选中时是灰色的。

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

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.
    self.tabBarController?.tabBar.unselectedItemTintColor = .white
}

但这画笔太宽泛了,因为它会为所有标签栏项目着色,而且它也会给图像着色。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 2016-05-11
    • 2012-11-02
    • 2016-07-02
    相关资源
    最近更新 更多