123456789101112131415161718192021222324252627282930313233343536 |
- import UIKit
- public protocol NavigationBackViewController: class {
- func setupNavigationBackItem()
- }
- public extension NavigationBackViewController 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: .touchDown)
- let backItem = UIBarButtonItem(customView: btn)
- let spaceItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
- spaceItem.width = -10
- navigationItem.leftBarButtonItems = [spaceItem, backItem]
- }
- }
- public extension UIViewController {
- @objc func backToViewController() {
- navigationController?.popViewController(animated: true)
- }
- }
|