ios13 - unSelectedItem 的 UITabBar tintColor 不工作

ios13 - UITabBar tintColor for unSelectedItem not working

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

override func viewDidLoad() {
    super.viewDidLoad()

    myTabbar.unselectedItemTintColor = .red
}

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
}
     

如果是: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
}