//
// NavigationController.m
//
#import "NavigationController.h"
@interface NavigationController ()
@end
@implementation NavigationController
/**
* 第一次使用的这个类的时候会调用(一个类只会调用一次)
*/
+ (void)initialize
{
//1.设置导航栏主题
[self setupNavBarTheme];
//2.设置BarButtonItem的主题
[self setupBarButtonItemTheme];
}
/**
* 设置导航栏主题
*/
+ (void)setupNavBarTheme
{
UINavigationBar *navBar = [UINavigationBar appearance];
//背景图片
[navBar setBackgroundImage:[UIImage imageNamed:@"NavBar"] forBarMetrics:UIBarMetricsDefault];
//状态栏为白色样式
navBar.barStyle = UIBarStyleBlack;
//返回箭头颜色
navBar.tintColor = [UIColor whiteColor];
//设置标题文字属性
NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
attrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
//attrs[NSFontAttributeName] = [UIFont systemFontOfSize:16];
[navBar setTitleTextAttributes:attrs];
}
/**
* 设置BarButtonItem的主题
*/
+ (void)setupBarButtonItemTheme
{
UIBarButtonItem *item = [UIBarButtonItem appearance];
//设置文字
NSMutableDictionary *itemAttrs = [NSMutableDictionary dictionary];
itemAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
[item setTitleTextAttributes:itemAttrs forState:UIControlStateNormal];
}
/**
* 重写Push方法(隐藏底部的tabbar)
*/
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if (self.viewControllers.count) { //避免一开始就隐藏了
viewController.hidesBottomBarWhenPushed = YES;
}
[super pushViewController:viewController animated:animated];
}
@end