对于添加到UIViewController的自定义导航项,后退按钮不可见

时间:2017-08-31 11:23:23

标签: ios iphone swift3 uiviewcontroller back

从其中一个视图控制器(位于导航控制器中)以模态方式显示UIViewController 代码:

self.present(viewController, animated: true, completion: nil)

在模态ViewController中,添加了自定义导航栏以及导航项。其中,我正在尝试显示后退按钮。

let backButton = UIBarButtonItem()
backButton.title = "Back"
self.navigItem.backBarButtonItem = backButton  //self.navigItem is the custom Navigation Item

这里有什么遗失吗?

提前谢谢, 拉杰什

2 个答案:

答案 0 :(得分:0)

 let btnleft : UIButton = UIButton(frame: CGRect(x:0, y:0, width:35, 
                           height:35))
 btnleft.contentMode = .center
 btnleft.setImage(Set_Local_Image("arrow_left"), for: .normal)
 btnleft.addTarget(self, action: #selector(YOUR_ACTION), for: .touchDown)

 let backBarButon: UIBarButtonItem = UIBarButtonItem(customView: btnleft)
 self.navigationItem.setLeftBarButtonItems([menuBarButon], animated:false)

答案 1 :(得分:0)

在Swift3中在viewDidLoad上尝试此代码

    self.navigationController?.navigationBar.backIndicatorImage = UIImage(named: "arrow_left")
    self.navigationController?.navigationBar.backIndicatorTransitionMaskImage = UIImage(named: "arrow_left")
    UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(0, -60), for:UIBarMetrics.default)
    self.navigationController?.navigationBar.tintColor = UIColor.white
    self.navigationItem.hidesBackButton = false