我有一个 View 层次结构
只有一个导航 Controller 和它的 rootViewController。
我想在圈出的 View 中添加一个左栏按钮项。
我要添加 barButton 的 View :
我试过了
self.navigationController?.navigationItem.leftBarButtonItem = editButtonItem
在 viewDidLoad()
和 viewWillAppear()
中,但都没有成功。
我还尝试在 Storyboard中添加 UINavigationItem
,然后添加 barButtonItem。这也不起作用。
编辑
我尝试了下面的答案,这就是我在输出中得到的结果。
尝试答案后的输出:
如有任何帮助,我们将不胜感激。
最佳答案
你可以像这样添加条形按钮
let btnleft : UIButton = UIButton(frame: CGRect(x:0, y:0, width:35, height:35))
btnleft.setTitleColor(UIColor.white, for: .normal)
btnleft.contentMode = .left
btnleft.setImage(UIImage(named :"yourimage.png"), for: .normal)
btnleft.addTarget(self, action: #selector(YOUR_ACTION), for: .touchDown)
let backBarButon: UIBarButtonItem = UIBarButtonItem(customView: btnleft)
self.navigationItem.setLeftBarButtonItems([backBarButon], animated: false)
关于ios - 在 rootView Swift 3.0 之后以编程方式在 ViewControllers 添加栏按钮项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45413358/