Nessuna descrizione

NavigationBackDelegate.swift 1.1KB

    // // NavigationBackDelegate.swift // PaiaiUIKit // // Created by ffib on 2019/1/11. // Copyright © 2019 yb. All rights reserved. // 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: .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) } }