简体   繁体   English

如何在iOS的标签栏中更改未选中图像的色调颜色?

[英]how do you change the tint color of an unselected image in a tab bar in iOS?

如何在iOS的标签栏中更改未选中图像的色调颜色?

Unfortunately, there's no way to do that. 不幸的是,没有办法做到这一点。 There was a feature allowing you to do that, but it was removed in iOS 7 and has never been restored. 有一个功能可以使您执行此操作,但是它已在iOS 7中删除,并且从未还原。

Your only option, if you want that kind of control, is not to use the tint color at all, but to set the image and the selected image, as normal images (rendered using AlwaysOriginal , not template images). 如果要进行这种控制,唯一的选择就是根本不使用色调颜色,而是将图像和所选图像设置为普通图像(使用AlwaysOriginal渲染,而不是模板图像渲染)。 That way, there's no tinting, and the selected image is used when the item is selected, and the regular image is used when it is not, and the colors are completely up to you. 这样,就不会有色彩,选择项目时将使用选定的图像,而没有选择时将使用常规图像,并且颜色完全取决于您。

You can can set the tab bar image tint color for the selected image programmatically, then if you want to tint the unselected image you should make the image yourself with the desired color. 您可以通过编程方式为所选图像设置标签栏图像的着色颜色,然后,如果要对未选择的图像进行着色,则应使图像自己具有所需的颜色。 I like to do the same color as my selected image but with 50% opacity. 我喜欢使用与所选图像相同的颜色,但不透明度为50%。 The code looks like this: 代码如下:

UIImage *item2Image = [[UIImage imageNamed:@"simulatorTabBarIconUnselected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *item2ImageSelected = [[UIImage imageNamed:@"simulatorTabBarIconSelected"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UITabBarItem *tabBarItem2 = [[UITabBarItem alloc] initWithTitle:@"Simulator" image:item2Image selectedImage:item2ImageSelected];

The always rendering mode UIImageRenderingModeAlwaysOriginal means the unselected image will appear as it is in your image assets folder, whereas the UIImageRenderingModeAlwaysTemplate will cause the image to appear as the tint color you've specified. 始终呈现模式UIImageRenderingModeAlwaysOriginal表示未选择的图像将显示在图像资源文件夹中,而UIImageRenderingModeAlwaysTemplate将使图像显示为您指定的色泽。 You can see how this looks here: 您可以在这里看到外观:

http://www.apppicker.com/apps/1059513718/jetfuel-by-beaconsinspace http://www.apppicker.com/apps/1059513718/jetfuel-by-beaconsinspace

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM