11

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
}
  • https://stackoverflow.com/a/58088270/8374890 for iOS 13+ – Keshu R. Feb 03 '20 at 11:22
  • try this: self.tabBar.unselectedItemTintColor = [UIColor lightGrayColor]; – Mayank Feb 03 '20 at 11:31
  • 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 2](https://stackoverflow.com/questions/56839374/uitabbaritem-icon-not-colored-correctly-for-ios-13-when-a-bar-tint-color-is-spec) – Jawad Ali Feb 03 '20 at 11:57

2 Answers2

19

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
}
     
Mudith Chathuranga Silva
  • 7,253
  • 2
  • 50
  • 58
  • 1
    Note: you need to use `inlineLayoutAppearance` instead of `stackedLayoutAppearance` if you are using inline layouts (like on an iPad). – Tad Aug 18 '22 at 18:23
  • 1
    And if you experience truncated titles with inlineLayoutAppearance, see this question: https://stackoverflow.com/a/69457332/1271867 – Tad Aug 18 '22 at 18:38
8

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

iDeveloper
  • 2,339
  • 2
  • 24
  • 38