首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >更改未选择的UITabBarController项目标题和背景图像的tintColor

更改未选择的UITabBarController项目标题和背景图像的tintColor
EN

Stack Overflow用户
提问于 2014-10-24 23:44:50
回答 3查看 26.6K关注 0票数 19

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

未选中状态的默认颜色是浅灰色,但它不会显示在我的深色UITabBar背景中

我希望我的未选中状态的颜色为UIColor blackColor

在我的应用委托中,我使用选项完成了启动:我有

代码语言:javascript
复制
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]];
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-10-25 01:24:55

想明白了!

使用此命令可更改文本的颜色:

代码语言:javascript
复制
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }
                                         forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
                                         forState:UIControlStateSelected];

并确保图像的图像呈现模式设置为原始模式

代码语言:javascript
复制
UIImage *deselectedImage = [[UIImage imageNamed:@"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
票数 47
EN

Stack Overflow用户

发布于 2014-10-25 00:02:13

application didFinishLaunchingWithOptions:内部的AppDelegate.m中,使用以下代码:

代码语言:javascript
复制
//unselected icon tint color 
[[UIView appearanceWhenContainedIn:[UITabBar class], nil] setTintColor:[UIColor redColor]];

//selected tint color 
[[UITabBar appearance] setTintColor:[UIColor greenColor]];

//text tint color 
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor whiteColor] }
                                     forState:UIControlStateNormal];

//background tint color 
[[UITabBar appearance] setBarTintColor:[UIColor blueColor]];
票数 26
EN

Stack Overflow用户

发布于 2016-06-06 03:54:47

您还可以在资源文件的属性检查器中将图像呈现为原始图像,而无需编写任何代码

票数 14
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26551458

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档