0

enter image description here

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?

1 Answer 1

1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.