setFinishedSelectedImage:withFinishedUnselectedImage:
is deprecated in iOS7. Apple recommends to use setters of image
and selectedImage
with UIImageRenderingModeAlwaysOriginal
instead. I can't find any example of how to use UIImageRenderingModeAlwaysOriginal
. So the question is really simple: how to set images for UITabBarItem
in iOS7?
If you're are trying to achieve displaying of the actual image at the UITabBar then use the following code.
[yourTabBarItem setImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
and if you want to display image in original condition for the selected then use the following
[yourTabBarItem setSelectedImage:[[UIImage imageNamed:@"more.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
these two are alternative to
setFinishedSelectedImage: withFinishedUnselectedImage:
The setFinishedSelectedImage
is deprecated because Apple wants to direct interfaces toward using the template images and the tintColor you select (or the Blue default.) So, the easy default does the Tab Bar Items that way.
If you need to still use the Icon image as designed, you create the image with the rendering mode for Always Original. Like:
[[UIImage imageNamed:@"YourIcon.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
To set the icon you need to get the tabBarItem
from the ViewController
. What I missed in my app was that each of my tabs had a NavigationController
wrapping the top view controller in the tab. Most answers about this subject don't mention getting the navigationContoller and that was key to getting it working in my app.
So, in my UITableViewContoller subclass I added the following to viewDidLoad.
- (void)viewDidLoad
{
[super viewDidLoad];
...
[self.navigationController.tabBarItem setSelectedImage:[[UIImage imageNamed:@"MySelectedIcon.png"]
imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal]];
}
The result was the Icon as designed when the tab was selected. If you leave off the imageWithRenderingMode method call, the Icon will be treated as a template colored with the tintColor. Hope this helps.
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