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

479 Views Asked by At

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.

enter image description here

1

There are 1 best solutions below

0
On

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.