Search code examples
swiftuitabbarcontrollertabbar

Disable tabbar item - Swift


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...


Solution

  • Here is the answer

    if  let arrayOfTabBarItems = tabBarViewController.tabBar.items as! AnyObject as? NSArray,tabBarItem = arrayOfTabBarItems[2] as? UITabBarItem {
            tabBarItem.enabled = false
        }