Add this category to your project. This will force the tab bar elements to use the original image as a disabled state instead of applying a gray gradient to them:
@implementation UItabBarItem (CustomUnselectedImage) - (UIImage *)unselectedImage { return self.image; } @end
It may seem like it is using private APIs, but I saw that it was used several times for applications that were approved. This is actually not a private method call, but simply an override.
If you need to specify different images for the selected and unselected images, it is best to use the property of the UITabBarItem tag and the switch statement, for example:
@implementation UItabBarItem (Custom) - (UIImage *)selectedImage { switch (self.tag) { case 1: return [UIImage imageNamed:@"tab-selected1.png"]; case 2: return [UIImage imageNamed:@"tab-selected2.png"]; etc... } } - (UIImage *)unselectedImage { switch (self.tag) { case 1: return [UIImage imageNamed:@"tab-unselected1.png"]; case 2: return [UIImage imageNamed:@"tab-unselected2.png"]; etc... } } @end
Then, in the interface builder, do not interfere with customizing the images of the tab bar items, as they will simply be ignored. Instead, set the tags according to the images specified in the switch statements.
Note that if an application has several tab stripes and you do not want all of them to be redefined in this way, you can define these methods in a subclass of UITabBarItem instead of a category. You can then set the class of tab bar items in the nib file as your own subclass instead of the usual UITabBarItems, and only those that will be affected will be affected.
EDIT:
Please note that with iOS 5 there is a better way to do this using the UIAppearance APIs. This method should still work, but who knows if Apple can start to fight it, there is now an officially supported approach. Itβs better to use the new method if you donβt need iOS 4 support.
source share