UITabBarItem图像颜色是灰色的,而原始图像的白色

问题描述:

我用下面的代码来创建图像我UITabBarItemUITabBarItem图像颜色是灰色的,而原始图像的白色

self.tabBarItem.image = [UIImage imageNamed:@"tab_img.png"]; 

这tab_img.png包括黑色,白色和清晰颜色的。但在应用程序中,黑白图像的所有部分变成灰色。我怎样才能将这个灰色变成白色?

this is image that I use

enter image description here

+0

您可以在此处添加图像吗? – Sagrian 2013-02-26 10:12:21

+0

我已添加此主页图片。 – 2013-02-26 10:22:57

图片UITabBarItems应该只是alpha通道! 不透明的部分会显示为灰色(如果选择蓝色),但!

看看:http://devinsheaven.com/creating-uitabbar-uitoolbar-icons-in-adobe-illustrator/

+0

UITabBarItems的图像可以是白色而不是灰色? – 2013-02-26 10:46:10

+0

https://github.com/rumex/RXCustomTabBar – blub 2013-02-26 11:11:14

+2

对于iOS 7+不适用。你可以使用' - imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal' – KPM 2014-09-25 20:29:15

我有同样的问题一次,我用的图像白色和阿尔法只有这样image

我选择self.tabBarItem.image = [UIImage imageNamed:@"Liste"];

+0

改变[UIImage imageNamed:@“tab_img.png”];改变[UIImage imageNamed:@“tab_img”];没有帮助 – 2013-02-26 10:48:14

+0

我编辑了我的答案,以更清晰地标记 – pmk 2013-02-26 10:49:37

集和未选定的图像设置。

[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"mehr_icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"mehr_icon"]]; 
+0

该方法在iOS 7中已弃用,在iOS 7或更高版本中使用@Cornel Damian方法。 – Henry 2014-06-30 09:17:07

+0

就是这样,tks @fibnochi – 2014-09-24 08:12:28

唯一的办法就是去IB(界面生成器),并在您的视图控制器选择UITabBarItem并进入“文件检查器”向下滚动,你会看到全球色调她,你可以将其设置为无颜色或您想要的任何颜色将对所选图像生效。

按照下面的代码是关注

setFinishedSelectedImage: withFinishedUnselectedImage:; 

这里不再提供的iOS 7,而我们可以用

[yourCustomTabBarItem setSelectedImage:---]; 

但是这也将以此为全球色调的色彩效果。

在iOS7,如果你使用IB你也可以继承的UITabBarController再补充一点:

+ (void)initialize 
{ 
    //the color for the text for unselected tabs 
    [UITabBarItem.appearance setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor redColor]} forState:UIControlStateNormal]; 

    //the color for selected icon 
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];  
} 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7) { 
     for (UITabBarItem *tbi in self.tabBar.items) { 
      tbi.image = [tbi.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]; 
     } 
    } 
} 
如果您创建的项目

manualy必须设置UIImageRenderingModeAlwaysOriginal上的每个图标,然后从初始化添加代码。

+0

好人。拯救了我的生命 – Liam 2014-05-21 09:35:35

+0

所选项目的文本也似乎受到第一行的影响。我不得不添加:[UITabBarItem.appearance setTitleTextAttributes:@ {NSForegroundColorAttributeName:[UIColor whiteColor]} forState:UIControlStateSelected];使选定的项目文本正确。 – 2014-07-29 20:29:25

+0

.....很好的回答) – BhushanVU 2014-12-12 11:37:46

如果您正在使用图像资源,只需设置域“渲染为”您的图像(选中和未选中图像)“原始图像”(example

然后在你的厦门国际银行设定的“图像”和“选择图像“选项栏上的字段项目 (example