美文网首页
导航栏返回按钮

导航栏返回按钮

作者: 橡树花香 | 来源:发表于2018-07-02 16:43 被阅读0次

整体替换导航栏按钮
@interface CustomNavigationVC : UINavigationController

@end

///////
@implementation CustomNavigationVC

  • (void)viewDidLoad {
    [super viewDidLoad];

    [self.navigationBar setShadowImage:[UIImage new]]; //导航栏下方1px横线
    self.interactivePopGestureRecognizer.delegate = (id <UIGestureRecognizerDelegate>)self;
    }

pragma mark - 返回按钮

  • (UIBarButtonItem *)createBackButton
    {
    return [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(popSelf)];
    }

  • (void)popSelf
    {
    [self popViewControllerAnimated:YES];
    }

pragma mark - 重写方法

  • (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
    {
    [super pushViewController:viewController animated:animated];

    if (viewController.navigationItem.leftBarButtonItem == nil && self.viewControllers.count > 1) {
    viewController.navigationItem.leftBarButtonItem = [self createBackButton];
    }
    }

相关文章

网友评论

      本文标题:导航栏返回按钮

      本文链接:https://www.haomeiwen.com/subject/qvuluftx.html