i pad tab bar unselected item color is not changing but working fine in iphone

24 Views Asked by At

i am using xcode version 14.3.1 . Minimum deployment target 12.0. in iphone everything is just working fine but in the i pad selected item color is changing but unselected item color is not changing.

i want to get the selected unselected color in ipad too

1

There are 1 best solutions below

0
Parul Garg On BEST ANSWER
let tabBarAppearnace = UITabBarAppearance()
let tabFont =  UIFont.boldSystemFont(ofSize: 16)
let selectedAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.white]

let normalAttributes: [NSAttributedString.Key: Any]
        = [NSAttributedString.Key.font: tabFont, NSAttributedString.Key.foregroundColor: UIColor.red]

tabBarAppearnace.stackedLayoutAppearance.normal.titleTextAttributes = normalAttributes
        tabBarAppearnace.stackedLayoutAppearance.selected.titleTextAttributes = selectedAttributes

tabBar.standardAppearance = tabBarAppearnace

If the above doesn't work try the below mentioned code

tabBarAppearnace.inlineLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.inlineLayoutAppearance.selected.titleTextAttributes = selectedAttributes

tabBarAppearnace.compactInlineLayoutAppearance.normal.titleTextAttributes = normalAttributes
tabBarAppearnace.compactInlineLayoutAppearance.selected.titleTextAttributes = selectedAttributes