整体替换导航栏按钮
@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];
}
}
网友评论