Brak opisu

NavigationBackDelegate.swift 1.1KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. // NavigationBackDelegate.swift
  3. // PaiaiUIKit
  4. //
  5. // Created by ffib on 2019/1/11.
  6. // Copyright © 2019 yb. All rights reserved.
  7. //
  8. import Foundation
  9. public protocol NavigationBackDelegate: class {
  10. func setupNavigationBackItem()
  11. }
  12. public extension NavigationBackDelegate where Self: UIViewController {
  13. func setupNavigationBackItem() {
  14. let btn = UIButton(type: .system)
  15. btn.contentHorizontalAlignment = .left
  16. btn.frame = CGRect(x: 0, y: 0, width: 40 , height: 40)
  17. btn.setImage(UIImage(named: "navigation-back"), for: .normal)
  18. btn.addTarget(self, action: #selector(backToViewController), for: .touchUpInside)
  19. let backItem = UIBarButtonItem(customView: btn)
  20. let spaceItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
  21. spaceItem.width = -10
  22. navigationItem.leftBarButtonItems = [spaceItem, backItem]
  23. }
  24. }
  25. fileprivate extension UIViewController {
  26. @objc func backToViewController() {
  27. navigationController?.popViewController(animated: true)
  28. }
  29. }