I'm currently developing an iOS-App which will have 5 tabbar-icons. One of these should only be visible if you are allowed to see it. How can I hide this icon?
Asked
Active
Viewed 72 times
0
-
You can add / remove tabBarItems at run time to achieve this. – Bhavik Modi May 30 '19 at 09:29
-
self.tabBarController?.tabBar.hidden = true/false – Yogesh Patel May 30 '19 at 09:37
-
@BhavikModi How can I do that? – Abc May 30 '19 at 09:42
-
@YogeshPatel This hides the complete tabbar not a specific icon. – Abc May 30 '19 at 09:42
-
Okay try this way tabBarController.viewControllers?.remove(at:0) – Yogesh Patel May 30 '19 at 09:44
-
also check this url :- https://stackoverflow.com/questions/28384321/remove-tabbar-item-in-swift this question is already ask many times – Yogesh Patel May 30 '19 at 09:51
2 Answers
1
If you want to remove the UIViewController
from tabBar
, add this line of code in the UITabBarControllerClass
For removal
self.viewControllers?.remove(at: tabIndex) // replace the tabIndex which you want to remove
For Add
self.viewControllers?.insert(viewController, at: tabIndex) // replace the viewcontroller with your controller and tabIndex with your index

Harsh Pipaliya
- 2,260
- 1
- 14
- 30

s4salman
- 121
- 6
-
1I did it in a ViewController with `self.tabBarController?.viewControllers?` instead of in the UITabBarControllerClass. This did work too. – Abc May 30 '19 at 10:12
0
With the following code, you can remove the specified tab from tab bar:
let tabIndex = 3
if let tabBarController = self.tabBarController {
if tabIndex < tabBarController.viewControllers?.count {
var allViewControllers = tabBarController.viewControllers
allViewControllers?.remove(at: tabIndex)
tabBarController.viewControllers = allViewControllers
}
}

Bhavik Modi
- 1,517
- 14
- 29