Ronnie L
Ronnie L

Reputation: 123

How to hide / disable tab bar item in swift

I have a five tab, tab bar controller in my app, and I want to only show the 5th item if a manager is logged into the app (instead of employee).

I currently have this code which disables the 5th item but I can still see it (its just grayed out and is not clickable).

self.tabBarController!.tabBar.items![4].enabled = false

Is there a way to only show the first four items and evenly space them if a non manager is logged in?

Upvotes: 3

Views: 4130

Answers (1)

Allen
Allen

Reputation: 3207

Swift 3

if let tabBarController = self.tabBarController {
    let indexToRemove = 3
    if indexToRemove < tabBarController.viewControllers!.count {
        var viewControllers = tabBarController.viewControllers
        viewControllers?.remove(at: indexToRemove)
        tabBarController.viewControllers = viewControllers
    }
}

Upvotes: 1

Related Questions