简体   繁体   English

如何在tabBar中更改未选择图片的色调颜色

[英]How to change tint color of the UNSELECTED pictures in a tabBar

在此处输入图片说明

If I do self.tabBar.tintColor = [UIColor whiteColor]; 如果我这样做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? 如何获得未选中的选项卡栏的图像为黑色,深灰色或红色?

You can use something like this. 您可以使用类似这样的东西。 The clue of this line of code is UIImageRenderingModeAlwaysOriginal . 这行代码的线索是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 在每个TabBarItem的第一个ViewController添加此代码

- (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]; 现在,您不需要self.tabBar.tintColor = [UIColor whiteColor]; any more. 还有。

Rendering Modes by Apple Documentation: Apple文档的渲染模式:

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 检查此答案: stackoverflow.com/a/22766669/1381708

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

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