Search code examples
iosswiftuitabbarcontrolleruitabbaruitabbaritem

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?


Solution

  • 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