更改未选中的UITabBarController项目标题和背景图像的tintColor [英] Change tintColor of unselected UITabBarController item title and background image

查看:160
本文介绍了更改未选中的UITabBarController项目标题和背景图像的tintColor的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改未选中的UITabBarItem标题和背景图像iOS 8的tintColor?

How can I change the tintColor of an unselected UITabBarItem title and background image iOS 8?

未选择状态的默认颜色是浅灰色,但在我的黑色阴影上不显示UITabBar背景

The default color for an unselected state is a light gray color, but it does not show on my darkish shade UITabBar background

我希望我的未选择状态的颜色为[UIColor blackColor]

I'd like my unselected state to have a color of [UIColor blackColor]

在我的应用代表中,didfinishlaunchingwithoptions:我有

Inside my app delegate didfinishlaunchingwithoptions: I have

UIImage *deselectedE = [[UIImage imageNamed:@"mincraft_axe_green_32.png"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
UIImage *selectedE = [[UIImage imageNamed:@"mincraft_axe_green_32.png"] imageWithRenderingMode:UIImageRenderingModeAutomatic];
e.tabBarItem =  [[UITabBarItem alloc] initWithTitle:@"Profile" image:deselectedE selectedImage:selectedE];
[[UITabBar appearance] setTintColor:[UIColor blackColor]];


推荐答案

想出来!

用它来改变文本的颜色:

Use this to change the color of the text:

[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }
                                         forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
                                         forState:UIControlStateSelected];

并确保图像的图像渲染模式设置为ORIGINAL

And make sure that image rendering mode is set to ORIGINAL for the images

UIImage *deselectedImage = [[UIImage imageNamed:@"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

这篇关于更改未选中的UITabBarController项目标题和背景图像的tintColor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆