Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using custom selected and unselected images on UITabBarItem

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 viewDidLoadand viewWillAppearmethods, 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,

like image 388
neutrino Avatar asked Dec 11 '22 16:12

neutrino


1 Answers

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"]];

}
like image 94
pdrcabrod Avatar answered Dec 28 '22 10:12

pdrcabrod