Hide item in UITabbar?

Is it a way to hide / show UITabbar element? I know I can remove and add, but what about hide? Latter I might need to show it again.

tabBar1.items!.remove(at: 1)

2 answers

  • answered 2018-11-08 07:03 Aditya Srivastava

    You can't hide/show UITabBarItem . The reason is UITabBarItem inherits from UIBarItem which further inherits from NSObject. Hence, there is no UIView (which contains isHidden property ) class in any of the inheritance level.

  • answered 2018-11-08 07:49 Natarajan

    If hide/show property given for tabBar items, there will be a blank space in tabBar which will give bad UI experience. So you can't hide/show tabBarItem as Aditya mentioned above.

    But If you want to add a tabBarItem initially and want to make it enabled only after some time, add it to the tabBar in disabled state as like below example.

    let tabBar = UITabBar(frame: CGRect(x: 0.0, y: 0.0, width: 320.0, height: 44.0))
    let tabItem1 = UITabBarItem(tabBarSystemItem: .history, tag: 0) 
    tabItem1.isEnabled = false
    let tabItem2 = UITabBarItem(tabBarSystemItem: .favorites, tag: 1)        
    tabBar.setItems([tabItem1, tabItem2], animated: true)
    //Enable your tabItem1 when needed
    tabBar.items![0].isEnabled = true