// // BackButton.swift // Twear // // Created by yangbin on 2021/11/16. // import UIKit /// 导航栏左侧返回按钮 class BackButton: UIButton { init(target: Any, action: Selector) { super.init(frame: CGRect(x: 0, y: 0, width: 22, height: 36)) commonInit(target: target, action: action) } required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } func commonInit(target: Any, action: Selector) { self.adjustsImageWhenHighlighted = false self.setImage(UIImage(named: "nav_back"), for: UIControl.State.normal) self.setImage(UIImage(named: "nav_back"), for: UIControl.State.highlighted) self.imageView?.contentMode = UIView.ContentMode.scaleAspectFit self.imageEdgeInsets = UIEdgeInsets(top: 0, left: -(self.frame.size.width > 20 ? self.frame.size.width - 20 : self.frame.size.width), bottom: 0, right:0) self.addTarget(target, action: action, for: .touchUpInside) } }