How to change tab bar item text color programmatically in iOS 15? It doesn't work like in iOS 14.

If you try to change the bar item text color programmatically like in iOS 14, it doesn't work in iOS 15.

For example:

 // https://stackoverflow.com/questions/2576592/changing-font-size-of-tabbaritem/

 UITabBarItem.appearance().setTitleTextAttributes(
   [NSAttributedString.Key.foregroundColor: UIColor.red],
   for: .normal)

This correctly changes the color when the tab bar is on top of a scroll view.

However, when the tab bar background becomes clear, all tab bar item text is red and not just the text for the currently selected tab.

Is this a bug in iOS 15? Or is this code wrong for iOS 15?

It sounds like a bug if all of your items turn red when you scroll away, they should retain their individual colors. Please file a bug with an attached sample.

Let's try to use stackedLayoutAppearance.

let tabBarAppearance = UITabBarAppearance()
let tabBarItemAppearance = UITabBarItemAppearance()

tabBarItemAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
tabBarItemAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.blue]

tabBarAppearance.stackedLayoutAppearance = tabBarItemAppearance

tabBar.standardAppearance = tabBarAppearance
tabBar.scrollEdgeAppearance = tabBarAppearance
How to change tab bar item text color programmatically in iOS 15? It doesn't work like in iOS 14.
 
 
Q