ios13 - UITabBar tintColor for unSelectedItem not working
Asked Answered
N

2

12

In Xcode 10 unselectedItemTintColor property working properly but after Xcode 11 with ios 13 UITabbar unselectedItemTintColor property not working.

override func viewDidLoad() {
    super.viewDidLoad()

    myTabbar.unselectedItemTintColor = .red
}
Newmint answered 3/2, 2020 at 11:20 Comment(3)
https://mcmap.net/q/247515/-uitabbaritem-icon-not-colored-correctly-for-ios-13-when-a-bar-tint-color-is-specified-in-interface-builder-in-xcode-11-beta-2 for iOS 13+Seaplane
try this: self.tabBar.unselectedItemTintColor = [UIColor lightGrayColor];Utica
Does this answer your question? UITabBarItem icon not colored correctly for iOS 13 when a bar tint color is specified in Interface Builder in Xcode 11, beta 2Zacharia
N
21

iOS 13 with 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
}
     
Newmint answered 3/2, 2020 at 12:59 Comment(2)
Note: you need to use inlineLayoutAppearance instead of stackedLayoutAppearance if you are using inline layouts (like on an iPad).Altocumulus
And if you experience truncated titles with inlineLayoutAppearance, see this question: https://mcmap.net/q/247516/-ipados-15-uitabbar-title-cut-offAltocumulus
T
11

In Case of : iOS 15 with 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
}

enter image description here

Trematode answered 20/4, 2022 at 6:13 Comment(2)
You're my hero! This is exactly what I was looking for the entire day! Thank you.Dutiful
"I'm thrilled to hear that it's working well for you! 😊" @DutifulTrematode

© 2022 - 2024 — McMap. All rights reserved.