UITabBarController unselected icon image tint

前端 未结 1 469
天命终不由人
天命终不由人 2021-01-16 19:19

I have a UITabBarController that I am trying to modify. Right now the UNselected tab icon images are default gray. I know that you cant change the tint of these UNselected

相关标签:
1条回答
  • 2021-01-16 19:40
    [[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    

    This isn't saving the image anywhere. Change it to:

    UIImage *myImage = [[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    

    And this:

    [self.tabBarItem initWithTitle:[nil]image:[UIImage imageNamed:@"white_stats.png"]selectedImage:[UIImage imageNamed:@"white_stats.png"]];
    

    nil isn't an object (it doesn't go in square brackets). Change this to:

    [self.tabBarItem initWithTitle:nil image:myImage selectedImage:[UIImage imageNamed:@"white_stats.png"]];
    

    Alternatively, you can technically do this in one line:

    [self.tabBarItem initWithTitle:nil image:[[UIImage imageNamed:@"white_stats.png"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[UIImage imageNamed:@"white_stats.png"]];
    

    But that is hard to read if you need to come back to it later, so don't do that.

    0 讨论(0)
提交回复
热议问题