Martin Hristov
Martin Hristov

Reputation: 111

tabbaritem image not changed

I am changing the image of a tabBarItem depending on a context

    if (user == nil) {
        self.navigationController?.tabBarItem.title = "Login"
        self.navigationController?.tabBarItem.image = UIImage(named: "login")
    } else {
        self.navigationController?.tabBarItem.title = "Home"
        self.navigationController?.tabBarItem.image = UIImage(named: "home")
        self.view = homeView()
    }

But when I have my view replaced by homeView the image is not changed, but the title is changed.

Logged screeen

Once I tab to other item I have it changed: enter image description here

How I can make it changed right after redirecting to the HomeView?

Upvotes: 0

Views: 159

Answers (1)

Eric
Eric

Reputation: 1213

I Think I found the problem (not tested yet). It doesn't work because there's a difference between the tabBar's image and it's selected image. Just add this line:

else {
    self.navigationController?.tabBarItem.title = "Home"
    self.navigationController?.tabBarItem.image = UIImage(named: "home")
    self.navigationController?.tabBarItem.selectedImage = UIImage(named: "home")
    self.view = homeView()
}

Upvotes: 1

Related Questions