重新繪制導航欄返回按鈕 代碼如下:
替換返回按鈕非常簡單,只需要在ViewController中創(chuàng)建一個UIBarButtonItem和一張圖片,并為按鈕添加相應的點擊事件即可--
- (void)viewDidLoad {[super viewDidLoad];
Do any additional setup after loading the view.
UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeSystem];
leftBtn.frame = CGRectMake(0, 0, 25,25);
[leftBtn setBackgroundImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
[leftBtn addTarget:self action:@selector(leftBarBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:leftBtn];
}
- (void)leftBarBtnClicked:(UIButton *)btn
{
[self.navigationController popViewControllerAnimated:YES];
}
手勢生效
如果自定義導航欄按鈕會使滑動手勢失效。只要重新添加導航欄的interactivePopGestureRecognizer的delegate手勢即可回歸。
self.navigationController.interactivePopGestureRecognizer.delegate = self;
本人個人微信公眾號地址(喜歡記得關注??)

辛小二個人微信公眾號地址