UITabBarItem图像颜色是灰色的,而原始图像的白色
我用下面的代码来创建图像我UITabBarItem
UITabBarItem图像颜色是灰色的,而原始图像的白色
self.tabBarItem.image = [UIImage imageNamed:@"tab_img.png"];
这tab_img.png包括黑色,白色和清晰颜色的。但在应用程序中,黑白图像的所有部分变成灰色。我怎样才能将这个灰色变成白色?
图片UITabBarItems应该只是alpha通道! 不透明的部分会显示为灰色(如果选择蓝色),但!
看看:http://devinsheaven.com/creating-uitabbar-uitoolbar-icons-in-adobe-illustrator/
集和未选定的图像设置。
[self.tabBarItem setFinishedSelectedImage:[UIImage imageNamed:@"mehr_icon"] withFinishedUnselectedImage:[UIImage imageNamed:@"mehr_icon"]];
该方法在iOS 7中已弃用,在iOS 7或更高版本中使用@Cornel Damian方法。 – Henry 2014-06-30 09:17:07
就是这样,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上的每个图标,然后从初始化添加代码。
您可以在此处添加图像吗? – Sagrian 2013-02-26 10:12:21
我已添加此主页图片。 – 2013-02-26 10:22:57