//
//  TRNavigationController.m
//  Open
//
//  Created by gao on 2016/11/9.
//  Copyright © 2016年 黄江涛 . All rights reserved.
//

#import "TRNavigationController.h"


@interface TRNavigationController ()

@end

@implementation TRNavigationController
+ (void)initialize
{
    if (self == [TRNavigationController class])
    {
        // 0.获取导航条外观
    
        UINavigationBar *bar = [UINavigationBar appearance];
        // 1.设置背景色
      //[bar setBarTintColor:[UIColor colorWithRed:27/255.0 green:132/255.0 blue:208/255.0 alpha:1.0]];

        [bar setBarTintColor:K_MainColor];
        
       
       
        // 2.设置背景图
//        [bar setBackgroundImage:[UIImage imageNamed:@"navigatio"] forBarMetrics:UIBarMetricsDefault];
//        [bar setBackgroundColor:[UIColor colorWithRed:35/255.0 green:168/255.0 blue:222/255.0 alpha:1]];

        [bar setShadowImage:[UIImage new]];
        
     
        // 3.设置左右按钮的文字颜色
        //[bar setTintColor:[UIColor whiteColor]];
        
        // 4.设置标题文字的垂直位置
        [bar setTitleVerticalPositionAdjustment:0 forBarMetrics:UIBarMetricsDefault];
        
        // 5.设置导航栏的样式--影响状态栏中文字的颜色
        [bar setBarStyle:UIBarStyleDefault];
        
        // 6.设置标题栏文字的样式
        NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
        attributes[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];
        attributes[NSForegroundColorAttributeName] = [UIColor whiteColor];
        [bar setTitleTextAttributes:attributes];
      
    }
}
- (void)viewDidLoad {
    [super viewDidLoad];
//   [self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:31/255.0 green:152/255.0 blue:218/255.0 alpha:1.0]];
    
   
     self.navigationBar.barTintColor = K_MainColor;
    
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];  
}
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.viewControllers.count > 0) {
        if (self.viewControllers.count == 1) {
            viewController.hidesBottomBarWhenPushed = YES;
        }
    } else {
        viewController.hidesBottomBarWhenPushed = NO;
    }

    [super pushViewController:viewController animated:animated];
}

// iOS14 popToRootViewControllerAnimated 底部tabbar消失问题处理
-(NSArray<__kindof UIViewController *> *)popToRootViewControllerAnimated:(BOOL)animated {
    if (animated) {
        UIViewController *popController = self.viewControllers.lastObject;
        popController.hidesBottomBarWhenPushed = NO;
    }
    return [super popToRootViewControllerAnimated:animated];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
