Reputation: 111
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.
Once I tab to other item I have it changed:
How I can make it changed right after redirecting to the HomeView?
Upvotes: 0
Views: 159
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