如何在ios7中更改非活动标签栏图标的颜色?

如何在ios7中更改非活动标签栏图标的颜色?,第1张

概述我想在ios7的标签栏中更改活动图标的颜色. 我知道如何将颜色设置为选定的TabBar项,但是我不知道如何将颜色设置为不活动的TabBar项. 有谁知道该怎么办? 提前致谢!! 这是我在appDelegate.m中的代码 //tint color for tabbar[UITabBar appearance].barTintColor = [UIColor colorWithRed:0.077 我想在ios7的标签栏中更改非活动图标的颜色.

我知道如何将颜色设置为选定的Tabbar项,但是我不知道如何将颜色设置为不活动的Tabbar项.

有谁知道该怎么办?
提前致谢!!

这是我在appDelegate.m中的代码

//tint color for tabbar[UITabbar appearance].barTintcolor = [UIcolor colorWithRed:0.077 green:0.411 blue:0.672 Alpha:1.000];//tint color for the text of inactive tabbar item.[[UITabbarItem appearance] setTitleTextAttributes:@{NSForegroundcolorAttributename:        [UIcolor whitecolor]} forState:UIControlStatenormal];//tint color for the text of selected tabbar item.[[UITabbarItem appearance] setTitleTextAttributes:@{NSForegroundcolorAttributename:        [UIcolor orangecolor]} forState:UIControlStateSelected];//tint color for the selected tabbar item.[[UITabbar appearance] setTintcolor:[UIcolor whitecolor]];//tint color for the inactive tabbar items.//Question:how can I set tint color for the inactive tabbar items???
解决方法 确实没有简单的方法来改变不活动图像的颜色.根本不可能在故事板中做到这一点.有一个非常直截了当的解决方案 – 只需使用imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal渲染模式将项目分配给一个图像.

鉴于您的图像最初已经为无效状态着色,您可以使用以下实现创建一个简单的UITabbarItem子类

@implementation P2TabbarItem- (voID)awakeFromNib {    [self setimage:self.image]; // calls setter below to adjust image from storyboard / nib file}- (voID)setimage:(UIImage *)image {    [super setimage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];    self.selectedImage = [image imageWithRenderingMode:UIImageRenderingModeAlwaystemplate];}@end

在您的故事板中,将所有UITabbarItems的Class字段填充到新创建的子类名称 – 就是这样!

总结

以上是内存溢出为你收集整理的如何在ios7中更改非活动标签栏图标的颜色?全部内容,希望文章能够帮你解决如何在ios7中更改非活动标签栏图标的颜色?所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存