Custom backBarButtonItem in Swift.
1. Add the following line to your Podfile:
platform :ios, '9.0'
target 'YourIosApps' do
use_frameworks!
pod 'MBack'
end
2. Then, run the following command:
1、run the following command:
2、Add the following line to your Cartfile:
3、run the following command:
iOS 9.0+
swift 3+ and swift 4
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.MBackButton(image: "Your custom back image")
}
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
self.MBackButton(image: "Your custom back image", popMethod: ENUMPopMethod.Root, title: "Back")
}
自定义返回按钮后,屏幕左边缘滑动返回会失效,解决办法如下:
1、让 ViewController 继承 UIGestureRecognizerDelegate
override func viewDidLoad()
{
super.viewDidLoad()
self.navigationController?.interactivePopGestureRecognizer?.delegate = self
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool
{
if gestureRecognizer == self.navigationController?.interactivePopGestureRecognizer
{
return self.navigationController!.viewControllers.count > 1
}
return true
}