iphone – UITabBarItem图像颜色为灰色,原始图像为白色

iphone – UITabBarItem图像颜色为灰色,原始图像为白色,第1张

概述我使用以下代码为我的UITabBarItem创建图像 self.tabBarItem.image = [UIImage imageNamed:@"tab_img.png"]; 这个tab_img.png由黑色,白色和清晰的颜色组成.但在应用程序中,黑白的图像全部变成灰色.我怎么能把这个灰色变成白色? 在iOS7中,如果您使用IB,您可以将UITabBarController子类化,然后添加: + 我使用以下代码为我的UITabbarItem创建图像

self.tabbarItem.image = [UIImage imagenamed:@"tab_img.png"];

这个tab_img.png由黑色,白色和清晰的颜色组成.但在应用程序中,黑白的图像全部变成灰色.我怎么能把这个灰色变成白色?

解决方法 在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];        }    }}

如果您创建项目手册,您必须在每个图标上设置UIImageRenderingModeAlwaysOriginal,并从初始化中添加代码.

总结

以上是内存溢出为你收集整理的iphone – UITabBarItem图像颜色为灰色,原始图像为白色全部内容,希望文章能够帮你解决iphone – UITabBarItem图像颜色为灰色,原始图像为白色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1083741.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-27
下一篇2022-05-27

发表评论

登录后才能评论

评论列表(0条)

    保存