Sle*_*ers 17 uitabbaritem tintcolor ios bartintcolor ios8
如何更改未选中的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]];
Run Code Online (Sandbox Code Playgroud)
Sle*_*ers 47
弄清楚了!
使用它来更改文本的颜色:
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor greenColor] }
forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor] }
forState:UIControlStateSelected];
Run Code Online (Sandbox Code Playgroud)
并确保图像的图像渲染模式设置为ORIGINAL
UIImage *deselectedImage = [[UIImage imageNamed:@"deselectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *selectedImage = [[UIImage imageNamed:@"selectedImage"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
Run Code Online (Sandbox Code Playgroud)
The*_*eSD 24
在您的AppDelegate.m里面application didFinishLaunchingWithOptions:使用以下代码:
//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]];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26147 次 |
| 最近记录: |