通过UIAppearance设置一些UI的全局效果
- 使用appearance设置TabBarItem文字效果最好采用全局的设置,在所有界面初始化前开始设置,否则可能失效。
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor lightGrayColor]} forState:UIControlStateNormal];
[[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName:[UIColor orangeColor]} forState:UIControlStateSelected];
单独对每个TabBarItem设置
NSArray * imageName = [NSArray arrayWithObjects:@"",@"", @"",@"",nil];//默认图片
NSArray * imageSelect = [NSArray arrayWithObjects:@"",@"",@"",@"",nil];//设置选中图片
for (int i = 0; i<imageName.count; i++) {
UIImage * normalImage = [[UIImage imageNamed:[imageName objectAtIndex:i]]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage * selectImage = [[UIImage imageNamed:[imageSelect objectAtIndex:i]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIViewController * vc = self.viewControllers[i];
[vc.tabBarItem setImage:normalImage];
[vc.tabBarItem setSelectedImage:selectImage];
vc.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);//如果美工帮你把文字也写上了,你就需要调整一下tabBarItem位置
}```
######UIImageRenderingMode枚举值来设置图片的renderingMode属性。该枚举中包含下列值:
- UIImageRenderingModeAutomatic // 根据图片的使用环境和所处的绘图上下文自动调整渲染模式。
- UIImageRenderingModeAlwaysOriginal // 始终绘制图片原始状态,不使用Tint Color。
- UIImageRenderingModeAlwaysTemplate // 始终根据Tint Color绘制图片,忽略图片的颜色信息。
网友评论