Reputation: 33138
If I do self.tabBar.tintColor = [UIColor whiteColor];
I manage to get the image of the selected tab bar white.
How do I get the image of the unselected tab bar black, or dark grey or red?
Upvotes: 0
Views: 160
Reputation: 8225
You can use something like this. The clue of this line of code is UIImageRenderingModeAlwaysOriginal
. That means that the code is showing the original image. If your image is red, the icon will be red and if your image is blue, your icon will be blue.
Add this code in the first ViewController
for every TabBarItem
- (void)viewDidLoad
{
[super viewDidLoad];
self.tabBarItem.image = [[UIImage imageNamed:@"yourImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
self.tabBarItem.selectedImage = [[UIImage imageNamed:@"yourImage.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
...
{
Now, you don't need your self.tabBar.tintColor = [UIColor whiteColor];
any more.
Rendering Modes by Apple Documentation:
UIImageRenderingModeAutomatic, // Use the default rendering mode for the context where the image is used
UIImageRenderingModeAlwaysOriginal, // Always draw the original image, without treating it as a template
UIImageRenderingModeAlwaysTemplate, // Always draw the image as a template image, ignoring its color information
Check this answer: stackoverflow.com/a/22766669/1381708
Upvotes: 1