如何更改未选中的UITabBarItem标题和背景图像iOS 8的tintColor?
未选中状态的默认颜色是浅灰色,但它不会显示在我的深色UITabBar背景中
我希望我的未选中状态的颜色为UIColor blackColor
在我的应用委托中,我使用选项完成了启动:我有
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]];
发布于 2014-10-25 01:24:55
想明白了!
使用此命令可更改文本的颜色:
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
forState:UIControlStateSelected];
并确保图像的图像呈现模式设置为原始模式
UIImage *deselectedImage = [[UIImage imageNamed:@"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
发布于 2014-10-25 00:02:13
在application didFinishLaunchingWithOptions:
内部的AppDelegate.m中,使用以下代码:
//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]];
发布于 2016-06-06 03:54:47
您还可以在资源文件的属性检查器中将图像呈现为原始图像,而无需编写任何代码
https://stackoverflow.com/questions/26551458
复制相似问题