6

I have a TabBar in my project and when user select item this item will disable but the color will change too! I want the color is same as other items color in TabBar I used

item.isEnabled = false

for disable item but this codes here won't work for this item

 override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    self.tabBar.barTintColor = UIColor.init(red: 126/255, green: 0/255, blue: 64/255, alpha: 1.0)
    if #available(iOS 10.0, *) {
        self.tabBar.unselectedItemTintColor = UIColor.white
        self.tabBar.unselectedItemTintColor = UIColor.white

    } else {
        // Fallback on earlier versions
    }
    UITabBar.appearance().tintColor = UIColor.white

}
Saeed Rahmatolahi
  • 1,317
  • 2
  • 27
  • 60
  • If you want to change the color of the selected item then give that color as UITabBar.appearance().tintColor – Aravind A R Jul 31 '17 at 07:17
  • no you didn't understand what I want - when user tap one of the item it will be disable but the color of that will change too I want the color doesn't change even when item is disable - remember that the item is disable not deselected – Saeed Rahmatolahi Jul 31 '17 at 07:21
  • Yup I meant that only the disabled item is the item which the user selects right ? – Aravind A R Jul 31 '17 at 07:23
  • yes when user select item it will be disable But I don't want to change the color I want disable item color is similar to the enable items do we have in swift ? – Saeed Rahmatolahi Jul 31 '17 at 08:08
  • Did you find a solution for your problem? I have the same problem:-) – debbiedowner Sep 18 '18 at 08:16

2 Answers2

2

Try this code -

UITabBar.appearance().tintColor = UIColor.gray
UITabBar.appearance().unselectedItemTintColor = UIColor.gray

Hope this helps!

Abhishek Jain
  • 4,557
  • 2
  • 32
  • 31
0

you can use the UITabBarControllerDelegate method in order to disable the selection

try this code 

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
    return false
    }
Faiz
  • 91
  • 1
  • 5