Brak opisu

NavigationBackItemDelegate.swift 1.1KB

    // // NavigationBackItemDelegate.swift // PaiaiUIKit // // Created by ffib on 2019/1/11. // Copyright © 2019 yb. All rights reserved. // import Foundation public protocol NavigationBackViewController e: 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] } } fileprivate extension UIViewController { @objc func backToViewController() { navigationController?.popViewController(animated: true) } }