方案一:
[UINavigationBar appearance].backIndicatorTransitionMaskImage = [UIImage imageNamed:@"backArrowMask.png"];
[UINavigationBar appearance].backIndicatorImage = [UIImage imageNamed:@"icon_arrowback_n”];
// 这两个属性必须同时设置才能生效
方案二:
if (navigationController?.childViewControllers.count ?? 0) > 1 {
navigationItem.leftBarButtonItem = UIBarButtonItem( image: UIImage(named: "ic_back_red"),
style:.plain,
target: self,
action: #selector(backButtonPressed))
}
方案二会导致手势侧滑返回失效,解决办法如下:
class BaseNavgationController: UINavigationController, UIGestureRecognizerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
interactivePopGestureRecognizer?.delegate = self
}
// 自定义的cancelItem需要自己实现手势返回
func gestureRecognizerShouldBegin(_ gestureRecognizer: UIGestureRecognizer) -> Bool {
if childViewControllers.count == 1 {
return false
}else {
return true
}
}
}
网友评论