NavigationController中设置UINavigationBar的样式

#import "CpNavigationController.h"

@interface CpNavigationController ()

@end

@implementation CpNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationItem setTitle:@"111"];
}

- (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.
}
*/
#warning 第一次调用该类时调用
+ (void)initialize
{
    if (self == [CpNavigationController class]) {
        //判断当前设备系统,
        CGFloat sysVersion =  [[UIDevice currentDevice].systemVersion floatValue];
        //根据不同的系统显示不同导航条背景图片
        NSString *navBarBackgroudImageName;
        if (sysVersion >=7.0) {
            navBarBackgroudImageName = @"NavBar64";
        }else{
            navBarBackgroudImageName = @"NavBar";
        }
        
        UINavigationBar *navBar = [UINavigationBar appearance];
//        [navBar setTintColor:[UIColor redColor]];
        
        [navBar setBackgroundImage:[UIImage imageNamed:navBarBackgroudImageName] forBarMetrics:UIBarMetricsDefault];
        
        //顶部导航条字体设置
        NSDictionary *dict = @{
                               NSForegroundColorAttributeName : [UIColor whiteColor],
                               NSFontAttributeName : [UIFont systemFontOfSize:15]
                               };
        [navBar setTitleTextAttributes:dict];
        
        //返回按钮字体颜色
        [navBar setTintColor:[UIColor whiteColor]];
    }
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{

    //隐藏底部bar
    viewController.hidesBottomBarWhenPushed = YES;
    
    return [super pushViewController:viewController animated:animated];
}

@end


你可能感兴趣的:(NavigationController中设置UINavigationBar的样式)