I'm trying to set my own images as selected and unselected images on a UITabBarItem, but no luck. I've tried the following code in the view controller viewDidLoad
and viewWillAppear
methods, but neither works:
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"on_rojo"] withFinishedUnselectedImage:[UIImage imageNamed:@"on"]];
What am I doing wrong? I've read also: iOS 5: UITabBarItem setFinishedSelectedImage:withFinishedUnselectedImage: not working / ignored, but I've created my UITabBarController on the IB, not programmatically. Is this the problem?
Thank you in advance,
You have to specify the images for every tab item. The following code is working for me
if ([[tabBarController.tabBar.items objectAtIndex:0] respondsToSelector:@selector(setFinishedSelectedImage:withFinishedUnselectedImage:)]) {
[[tabBarController.tabBar.items objectAtIndex:0] setFinishedSelectedImage:[UIImage imageNamed:@"blabla1.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble1.png"]];
[[tabBarController.tabBar.items objectAtIndex:1] setFinishedSelectedImage:[UIImage imageNamed:@"blabla2.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble2.png"]];
[[tabBarController.tabBar.items objectAtIndex:2] setFinishedSelectedImage:[UIImage imageNamed:@"blabla3.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble3.png"]];
[[tabBarController.tabBar.items objectAtIndex:3] setFinishedSelectedImage:[UIImage imageNamed:@"blabla4.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"bleble4.png"]];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With