微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我想在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字段填充到新创建的子类名称 – 就是这样!

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐