UINavigationBar+UITabbar总结

2019-03-15  本文已影响0人  独孤流

前言

虽然经常使用,但是每次用的时候又要查一堆资料,特此整理下

1、统一设置NavigationBar的颜色、tint颜色、、字体

// 设置导航栏的颜色
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
// 设置tint颜色
[[UINavigationBar appearance] setTintColor: [UIColor whiteColor]];
// 设置导航栏上的标题的颜色、字体
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:15]}];
// 取消透明度
[[UINavigationBar appearance] setTranslucent:NO];
// 设置背景图片
[[UINavigationBar appearance] setBackgroundImage:xxx forBarMetrics:UIBarMetricsDefault];
// 去掉导航栏与内容之间的分割线
[self.navigationController.navigationBar setShadowImage:nil];

2、设置tabbar相关

[[UITabBar appearance] setTintColor: [UIColor blueColor]];
    //Normal
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:12],NSBackgroundColorAttributeName:[UIColor greenColor]} forState:UIControlStateNormal];
    //Selected
[[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:15],NSBackgroundColorAttributeName:[UIColor redColor]} forState:UIControlStateSelected];

// 设置tabbar上的图片不要用tintcolor,使用图片原生的样子
UIImage *normalImg = [[UIImage imageNamed:@"xxx"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
vc.tabBarItem.image = normalImg;
UIImage *selectImg = [[UIImage imageNamed:@"xxx"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
vc.tabBarItem.selectedImage = selectImg;
// 将tabbar的颜色设置为黑色
self.tabBar.barTintColor = [UIColor blackColor]
上一篇 下一篇

猜你喜欢

热点阅读