在UIButton 类扩展中添加新的便利构造函数如下:
代码语言:javascript复制extension UIButton {
convenience init(composeForeImageName:String,composeBackImageName:String){
self.init()
setImage(UIImage.init(named: composeForeImageName), for: .normal)
setBackgroundImage(UIImage.init(named: composeBackImageName), for: .normal)
setBackgroundImage(UIImage.init(named: composeBackImageName "_highlighted"), for: .selected)
sizeToFit()
}
}
调用:调用的时候就会出现新的构造函数,方便便捷。
代码语言:javascript复制 //MARK:属性 懒加载
lazy var composeBtn = UIButton(composeForeImageName: "tabbar_compose_icon_add", composeBackImageName: "tabbar_compose_button")