Abc
Abc

Reputation: 55

How can I hide a UITabbarIcon?

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?

Upvotes: 0

Views: 75

Answers (2)

s4salman
s4salman

Reputation: 121

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

Upvotes: 1

Bhavik Modi
Bhavik Modi

Reputation: 1565

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

Upvotes: 0

Related Questions