繁体   English   中英

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

[英]Facing issue in iOS 15 change TabBar item text color

我的应用程序使用标签栏 controller 构建,我已经为选定的和正常的标签栏提供了自定义颜色,它在 iOS 14 和除 iOS 15 之外的所有标签栏都可以正常工作。 它在 iOS 15 中显示出更浅的灰色。

这是我的参考代码,我尝试了很多方法,但没有任何帮助。

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)
        }
    }

这是我的模拟器标签栏屏幕截图,左侧是 iOS 14,右侧是 iOS 15

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

我期望 iOS 15 中的 iOS 14 文本颜色相同

提前致谢!!!

我假设它不是自定义标签栏。

在您的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