12345678910111213141516171819202122232425262728293031323334353637 |
- import Foundation
- public protocol NavigationBackDelegate: class {
- func setupNavigationBackItem()
- }
- public extension NavigationBackDelegate where Self: UIViewController {
- func setupNavigationBackItem() {
- let btn = UIButton(type: .system)
-
- btn.contentHorizontalAlignment = .left
- btn.frame = CGRect(x: 0, y: 0, width: 40 , height: 40)
- btn.setImage(UIImage(named: "navigation-back"), for: .normal)
- btn.addTarget(self, action: #selector(backToViewController), for: .touchUpInside)
-
- let backItem = UIBarButtonItem(customView: btn)
- let spaceItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
- spaceItem.width = -10
-
- navigationItem.leftBarButtonItems = [spaceItem, backItem]
- }
- }
- fileprivate extension UIViewController {
- @objc func backToViewController() {
- navigationController?.popViewController(animated: true)
- }
- }
|