简体   繁体   中英

Facing issue in iOS 15 change TabBar item text color

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. Its showing much lighter grey in iOS 15.

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]
        let selected = [NSAttributedString.Key.font: textStyle.font, NSAttributedString.Key.foregroundColor: UIColor.tabBarForegroundActive]
        if #available(iOS 15.0, *) {
            let appearance = UITabBarAppearance()
            appearance.configureWithOpaqueBackground()
            appearance.stackedLayoutAppearance.normal.titleTextAttributes = normal
            appearance.stackedLayoutAppearance.selected.titleTextAttributes = selected
            self.tabBar.standardAppearance = appearance
            UITabBar.appearance().scrollEdgeAppearance = appearance
        } else {
            UITabBarItem.appearance().setTitleTextAttributes(normal, for: .normal)
            UITabBarItem.appearance().setTitleTextAttributes(selected, for: .selected)
        }
    }

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

https://i.stack.imgur.com/WSipK.png

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

Thanks in advance!!!

I am assuming it's not custom tabbar.

Add below line in your AppDelegate.swift didFinishLaunchingWithOptions .

UITabBar.appearance().unselectedItemTintColor = {ColorHere}

// In your case
UITabBar.appearance().unselectedItemTintColor = .black

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM