TintColor not changing for UIBarButtonItem for .normal stage in case of iOS 13.2

岁酱吖の 提交于 2021-01-28 03:42:24

问题


I have tried the almost max solution and it did not help, selected state color is applying but for a normal state, it's not applying. This issue I am facing specifically in iOS13.2 only.

        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)

I have disabled the dark mode in plist. It always shows as grayed out.


回答1:


It's a little unclear what the question is. It's a bug, or at least a serious behavior change, in iOS 13.

To see this, just make new project from the Tabbed App template and apply your code in the first view controller's initializer:

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)
    }
}

On iOS 12, the tab bar item text is yellow when selected and white when not selected. But in iOS 13, the bar item text is gray when not selected.

I have not found a satisfactory way to solve this. As suggested in a comment, you can say something like this:

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

But that's too broad a brush, because it tints all tab bar items and it tints the image too.

You can try using the new UITabBarItemAppearance class, but that has other undesirable side effects.

So apart from filing a bug report, there's not much you can do.



来源:https://stackoverflow.com/questions/58748592/tintcolor-not-changing-for-uibarbuttonitem-for-normal-stage-in-case-of-ios-13-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!