简体   繁体   English

iOS 15 中面临的问题更改 TabBar 项目文本颜色

[英]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.我的应用程序使用标签栏 controller 构建,我已经为选定的和正常的标签栏提供了自定义颜色,它在 iOS 14 和除 iOS 15 之外的所有标签栏都可以正常工作。 Its showing much lighter grey in iOS 15.它在 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这是我的模拟器标签栏屏幕截图,左侧是 iOS 14,右侧是 iOS 15

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

I am expecting same as iOS 14 text color in iOS 15我期望 iOS 15 中的 iOS 14 文本颜色相同

Thanks in advance!!!提前致谢!!!

I am assuming it's not custom tabbar.我假设它不是自定义标签栏。

Add below line in your AppDelegate.swift didFinishLaunchingWithOptions .在您的AppDelegate.swift didFinishLaunchingWithOptions中添加以下行。

UITabBar.appearance().unselectedItemTintColor = {ColorHere}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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