HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – UITabBarItem图像颜色为灰色,原始图像为白色大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我使用以下代码为我的UITabBarItem创建图像

@H_301_8@

@H_301_8@

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

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

解决方法

在iOS7中,如果您使用IB,您可以将uITabBarController子类化,然后添加

@H_301_8@

@H_301_8@

+ (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,并从初始化中添加代码.@H_301_8@

大佬总结

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

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

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。