NavigationController统一设置自定义导航条

创建个BaseNavigationController继承自UINavigationController
重写push方法

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated{
//设置导航条背景图片
    [self.navigationBar setBackgroundImage:[UIImage imageNamed:@"top_bg"] forBarMetrics:UIBarMetricsDefault];
//设置标题颜色
    self.navigationBar.tintColor = [UIColor whiteColor];
//通过Attributes设置标题字体颜色字号
    [self.navigationBar setTitleTextAttributes:@{@"NSForegroundColorAttributeName":[UIColor whiteColor]}];
    NSMutableDictionary *textAttrs = [NSMutableDictionary dictionary];
    textAttrs[NSForegroundColorAttributeName] = [UIColor whiteColor];
    textAttrs[NSFontAttributeName] = [UIFont boldSystemFontOfSize:18];
    [self.navigationBar setTitleTextAttributes:textAttrs];

//如果是根控制器就不显示返回按钮
    if (self.childViewControllers.count > 0) { // 非根控制器
        UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"button_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnPressed)];
        viewController.navigationItem.leftBarButtonItem = item;
    }
    [super pushViewController:viewController animated:animated];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容