首先来看三张图:
代码已贴出在图片下方
无文字返回按钮设置:
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault];
swift
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffset(horizontal: 0, vertical: -60), for: UIBarMetrics.default)
自定义返回按钮(位置与系统位置一致) 为UIViewController添加extension方法,方便调用
extension UIViewController{// xzCustomBackBarButtonItemfunc customBackBarButtonItem(target:AnyObject?,action:Selector?){var action1 = actionif action1 == nil {action1 = #selector(self.navigationController?.popViewController(animated:))}var target1 = targetif target1 == nil {target1 = self.navigationController}let backBarButtonItem = UIBarButtonItem.init(image: UIImage.init(named: "new-sys-jiantou"), style: UIBarButtonItemStyle.plain, target: target1, action: action1)//UIImage.init(named: "new-sys-jiantou") UI提供返回图片let fixBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: nil, action: nil)fixBarButtonItem.width = -10self.navigationItem.leftBarButtonItems = [fixBarButtonItem,backBarButtonItem]}}