Home > Software design >  iOS 15 How to change tab bar item text color programmatically
iOS 15 How to change tab bar item text color programmatically

Time:07-13

My app build with tab bar controller, i have given custom color for selected and normal tab bar and it’s working fine in iOS 14 and all but in iOS 15 it’s not working properly.

Here’s my code for reference and i have tried many ways but nothing helps me.

func updateTabBarItemFont() {
        self.tabBar.tintColor = UIColor.tabBarForegroundActive
        self.tabBar.barTintColor = UIColor.white
        self.tabBar.isTranslucent = false

        let textStyle = TextStyle.tabBarHeader
        let normal = [NSAttributedString.Key.font: textStyle.font, NSAttributedString.Key.foregroundColor: UIColor.neutralForegroundNormal]
        UITabBarItem.appearance().setTitleTextAttributes(normal, for: .normal)

        let selected = [NSAttributedString.Key.font: textStyle.font, NSAttributedString.Key.foregroundColor: UIColor.tabBarForegroundActive]
        UITabBarItem.appearance().setTitleTextAttributes(selected, for: .selected)
    }

Here's my simulator tabbar screen shot left side is iOS 14 and right side is iOS 15

I am expecting same as iOS 14 text color in iOS 15

Thanks in advance!!!

CodePudding user response:

tabBar.scrollEdgeAppearance is a new API on iOS 15 which must be set, setting the same appearance

Add below line at the bottom after setting standard appearance

tabBarController?.tabBar.scrollEdgeAppearance = tabBarController?.tabBar.standardAppearance
  • Related