修改导航栏返回按钮的图片
方法1:
[UINavigationBar appearance].backIndicatorTransitionMaskImage = [UIImage imageNamed:@"backArrowMask.png"];
[UINavigationBar appearance].backIndicatorImage = [UIImage imageNamed:@"icon_arrowback_n”];
icon_arrowback_n 大小为@2x = 42* 42
方法2:
UIButton * btn = [[UIButton alloc] init];
btn.frame = CGRectMake(0, 0, 30, 44);
UIImage * bImage = [[UIImage imageNamed: @"icon_back_bar.png"] resizableImageWithCapInsets: UIEdgeInsetsMake(0, 0, 0, 0)];
[btn addTarget: self
action: @selector(backButtonClick:)
forControlEvents: UIControlEventTouchUpInside];
[btn setImage: bImage forState: UIControlStateNormal];
UIBarButtonItem * lb = [[UIBarButtonItem alloc] initWithCustomView: btn];
UIBarButtonItem *negativeSpacer = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace
target:nil action:nil];
negativeSpacer.width = - 20;
if (self.navigationController.viewControllers.count > 1) {
self.navigationItem.leftBarButtonItems = @[negativeSpacer, lb];
}
自定义返回按钮会造成返回手势不能使用,解决方法
///处理自定义返回按钮后不能侧滑 @interface RootNavigationController : UINavigationController @end
@interface RootNavigationController : UINavigationController @end @implementation RootNavigationController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.interactivePopGestureRecognizer.delegate = self; } - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { if (self.childViewControllers.count == 1) { return NO; } return YES; }