How do I disable a particular tabbar item? Something like for the 3rd icon...
self.tabBarItem.items![2].enabled = false
There must be a way of doing such a simple task as a one liner? The above doesn't work...
Here is the answer
if let arrayOfTabBarItems = tabBarViewController.tabBar.items as! AnyObject as? NSArray,tabBarItem = arrayOfTabBarItems[2] as? UITabBarItem {
tabBarItem.enabled = false
}
Here's my code for doing the same, using Swift 3:
let tabBarControllerItems = self.tabBarController?.tabBar.items
if let tabArray = tabBarControllerItems {
tabBarItem1 = tabArray[0]
tabBarItem2 = tabArray[1]
tabBarItem1.isEnabled = false
tabBarItem2.isEnabled = false
}
Just put the block of code above in the viewDidLoad()
method for starters and don't forget to create the tabBarItem
variables and you're all good to go from there!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With