iOS 替换NavigationViewController返回(pop)按钮方法

在工程的BaseNavigationViewController中添加如下代码:

 - (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self.navigationBar setBarTintColor:[UIColor mainThemeColor]];
    self.navigationBar.tintColor = [UIColor whiteColor];
    [self.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor whiteColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:18]}];
}

 - (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{   //拦截所有push进来的子控制器
    if(self.viewControllers.count > 0)
    {
        viewController.hidesBottomBarWhenPushed = YES;
        
        viewController.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithImageNamed:@"back.png" targe:self action:@selector(backUp)];
        
    }
    [super pushViewController:viewController animated:animated];
    
}

 - (void)backUp
{
    [self popViewControllerAnimated:YES];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,950评论 25 709
  • 前几天看了@栾小布的一篇文章:Custom backBarButtonItem,在跟着做的时候我又顺便扩展了一些,...
    Dashing_Pro阅读 20,835评论 26 151
  • 有的时候更多的为我的表妹感到的是悲哀,父亲的冷漠严肃母亲的溺爱放任,在我辅导表妹做作业的时候体现的尤为深刻,我又...
    xuxy13阅读 1,852评论 0 0
  • 随着物质生活的不断丰富,人们的生活水平逐渐提高,可随之而来的,却是亚健康指数如井喷般增长。 每十个人中,至少有六到...
    陈晓依阅读 1,768评论 0 0
  • 那年,我大学毕业,刚参加工作,我们那个部门招了三个人,我跟另外两个,其中一个就是红叶。 对红叶的第一印象,感觉他是...
    白纸s阅读 1,222评论 0 0