一、
当用系统的uitabbarViewcontroller时,系统会默认的将选中状态的文字和图片进行渲染,一般情况下,每个app都会有自己的颜色。为此经过测试实践,一下方法可以将tabbarItem设置为自己想要的颜色。
方法1:
直接设置tabbarItem的Title文本的属性
[vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];
方法2:
可以通过设置tabbar的tintColor进行更改,如果用xib或者SB进行开发的,可以在tabbar中添加keyPath "tintColor"即可,方便简单
self.tabBar.tintColor = [UIColor colorWithRed:68/255.0 green:173/255.0 blue:159/255.0 alpha:1];
开发APP如果用代码添加根控制器,一般封装为一个方法来进行调用,如下:
- (void)createVC:(UIViewController *)vc Title:(NSString *)title imageName:(NSString *)imageName
{
vc.title = title;
self.tabBar.tintColor = [UIColor colorWithRed:68/255.0 green:173/255.0 blue:159/255.0 alpha:1];
vc.tabBarItem.image = [UIImage imageNamed:imageName];
NSString *imageSelect = [NSString stringWithFormat:@"%@_selected",imageName];
vc.tabBarItem.selectedImage = [[UIImage imageNamed:imageSelect] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
[self addChildViewController:[[UINavigationController alloc]initWithRootViewController:vc]];
}
二、
设置navigationBar颜色
1、有时候设置navigationBar的色值有偏差,原因是navigationBar自带模糊效果,关掉即可
self.navigationBar.translucent = NO;
2、storyboard设置navigationBar的颜色,XIb上没有属性设置 必须通过一下方法进行颜色或字体属性的设置
[self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:19.0]}];