问题描述:

I have a tab bar with 5 tabs. I have put different images for selected and unselected state of the tab bar items.

No matter what I do, the tint color does not change and it does not adapt the image color.

When the tab is selected, the color should be black and when unselected, it should be orange.

Here is an image of the attribute inspector with the images assigned.

Image of the tab bar

How do I change the image color?

网友答案:

The problem is that you can't control the tint color of the unselected items. That's not the fault of your code; it's just how iOS works. This used to be possible, but at some point (iOS 7? can't remember) it just went away.

So what's happening in your screen shot is that you've set the selected tint color to orange, and that's the end of that. One tab bar item is select and it is tinted orange.

网友答案:

One of the solution is to provide two sets of tab icons. There is a post which is very similar to your situation, you can take a look of it: Custom tab bar icon colors

I think this code (by Tunvir Rahman Tusher) is well explain:

UITabBarItem *tabBarItem1=[[tabBar items] objectAtIndex:0];//first tab bar
[tabBarItem1 setFinishedSelectedImage:[UIImage imageNamed:@"yourImageSelected.png"] withFinishedUnselectedImage:[UIImage imageNamed:@"yourImageUnselected.png"]];//image should be 30 by 30
相关阅读:
Top