-2

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)
János
  • 32,867
  • 38
  • 193
  • 353
  • You can't remove `UITabBar` item(s) like that. You'll get error: `Directly modifying a tab bar managed by a tab bar controller is not allowed.`. Instead of you should remove in this way: `self.viewControllers?.remove(at: 1)` inside your `UITabBarController`. – Mateusz Nov 08 '18 at 08:53
  • https://stackoverflow.com/questions/4037160/remove-uitabbaritem – m1sh0 Nov 08 '18 at 09:26

2 Answers2

1

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.

Aditya Srivastava
  • 2,630
  • 2
  • 13
  • 23
0

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
Natarajan
  • 3,241
  • 3
  • 17
  • 34