我想获得屏幕左侧的后退按钮,但我无法获得它
I want to get back button on left side of screen but I am unable to get it
file:///Users/anuragpanchal/Desktop/Simulator%20Screen%20Shot%20-%20iPhone%208%20Plus%20-%202018-10-11%20at%2014.18.24.png
我在视图上调用的后退按钮代码将出现 func
//MARK: Navigation button
func backNavigationButton() {
let button1 = UIBarButtonItem(image: UIImage(named: "back.png"), style: .plain, target: self, action: #selector(actionBackButton)) //
self.navigationItem.leftBarButtonItem = button1
}
@objc func actionBackButton() {
// PopToHome()
self.navigationController?.popViewController(animated: true)
}
iOS 的早期版本使用此代码:
let leftBarItem = UIBarButtonItem(image: leftImage, style: .done, target: target, action: leftImageSelector)
对于 iOS 11 或以上你需要添加一个垫片,因为苹果改变了按钮的布局:
let spacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: self, action: nil)
spacer.width = 5
self.navigationItem.leftBarButtonItems = [spacer, leftBarItem]
file:///Users/anuragpanchal/Desktop/Simulator%20Screen%20Shot%20-%20iPhone%208%20Plus%20-%202018-10-11%20at%2014.18.24.png
我在视图上调用的后退按钮代码将出现 func
//MARK: Navigation button
func backNavigationButton() {
let button1 = UIBarButtonItem(image: UIImage(named: "back.png"), style: .plain, target: self, action: #selector(actionBackButton)) //
self.navigationItem.leftBarButtonItem = button1
}
@objc func actionBackButton() {
// PopToHome()
self.navigationController?.popViewController(animated: true)
}
iOS 的早期版本使用此代码:
let leftBarItem = UIBarButtonItem(image: leftImage, style: .done, target: target, action: leftImageSelector)
对于 iOS 11 或以上你需要添加一个垫片,因为苹果改变了按钮的布局:
let spacer = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.fixedSpace, target: self, action: nil)
spacer.width = 5
self.navigationItem.leftBarButtonItems = [spacer, leftBarItem]