NavigationController的父類方法
對導航欄提前封裝好,比如按鈕,文字顏色,背景圖片和顏色
+ (void)initialize
{
UINavigationBar *navgationBar = [UINavigationBarappearance];
[navgationBar setShadowImage:[UIImagenew]];//設置陰影圖片
navgationBar.tintColor = [UIColorwhiteColor];//設置導航條顏色
CGFloat width = [UIScreenmainScreen].applicationFrame.size.width;
[navgationBar setBackgroundImage:[UIImageimageFromColor:[UIColornavigationTintColor]size:CGSizeMake(width,64)]forBarMetrics:UIBarMetricsDefault];//設置背景圖片和顏色
[navgationBar setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColorbarButtonItemTintColor]}];//設置文字顏色
}
- (void)viewDidLoad
{
[superviewDidLoad];
self.delegate =self;//設置自身的代理方法
self.interactivePopGestureRecognizer.delegate = self;
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated//重寫push的代理方法
{
if ([self.viewControllerscount] > 0) {
viewController.hidesBottomBarWhenPushed =YES;
}
[superpushViewController:viewControlleranimated:animated];
if ([self.viewControllerscount] > 1 && !viewController.navigationItem.leftBarButtonItem) {//判斷是否會根視圖
UIButton *backButton = [UIButtonbuttonWithType:UIButtonTypeCustom];
[backButton setImage:[UIImageimageNamed:@"nav_back"]forState:UIControlStateNormal];//設置返回按鈕圖片
backButton.bounds =CGRectMake(0,0,12,22);
[backButton addTarget:selfaction:@selector(backToPageAction)forControlEvents:UIControlEventTouchUpInside];
viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItemalloc]initWithCustomView:backButton];
}
}
- (void)backToPageAction//設置返回按鈕
{
[selfpopViewControllerAnimated:YES];
}