ios13 - unSelectedItem 的 UITabBar 色调颜色不起作用

Sah*_*vda 11 uitabbaritem uitabbar ios swift ios13

在 Xcode 10 中,unselectedItemTintColor 属性正常工作,但在 Xcode 11 和 ios 13 UITabbar 后,unselectedItemTintColor 属性不起作用。

override func viewDidLoad() {
    super.viewDidLoad()

    myTabbar.unselectedItemTintColor = .red
}
Run Code Online (Sandbox Code Playgroud)

Sah*_*vda 19

iOS 13 与 Xcode 11

if #available(iOS 13, *) {
     let appearance = UITabBarAppearance()
     appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.black]
     appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.red]
     appearance.stackedLayoutAppearance.normal.iconColor = UIColor.black
     appearance.stackedLayoutAppearance.selected.iconColor = UIColor.red
     myTabbar.standardAppearance = appearance
}
     
Run Code Online (Sandbox Code Playgroud)


iDe*_*per 9

如果是:iOS 15 和 Xcode 13

if #available(iOS 15, *) {
    let tabBarAppearance = UITabBarAppearance()
    tabBarAppearance.backgroundColor = .white
    tabBarAppearance.stackedLayoutAppearance.selected.titleTextAttributes = [.foregroundColor: UIColor.red]
    tabBarAppearance.stackedLayoutAppearance.normal.titleTextAttributes = [.foregroundColor: UIColor.black]
    tabBarAppearance.stackedLayoutAppearance.normal.iconColor = UIColor.black
    tabBarAppearance.stackedLayoutAppearance.selected.iconColor = UIColor.red
    tabBarView.standardAppearance = tabBarAppearance
    tabBarView.scrollEdgeAppearance = tabBarAppearance
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述