crz*_*777 9 iphone objective-c ios 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???
Run Code Online (Sandbox Code Playgroud)
Leo*_*zov 13
确实没有简单的方法来改变非活动图像的颜色.在故事板中似乎根本不可能做到.虽然有一个非常简单的解决方案 - 只需为项目分配一个具有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
Run Code Online (Sandbox Code Playgroud)
在您的故事板中,将所有UITabBarItem的Class字段填充到新创建的子类名称 - 就是这样!