Swift抽取基类

UILable

最低兼容8.2

import UIKit
extension UILabel {
    convenience init(text:String?, fontSize: CGFloat, weight: UIFont.Weight, color: UIColor, align: NSTextAlignment){
        self.text = text
        self.font = UIFont.systemFont(ofSize: fontSize, weight: weight)
        self.textColor = color
        self.textAlignment = align
    }
}

UIButton

最低兼容:8.2

import UIKit

extension UIButton{
    convenience init(text:String?, fontSize: CGFloat, weight: UIFont.Weight, color: UIColor){
        self.setTitle(text, for: .normal)
        self.titleLabel?.font = UIFont.systemFont(ofSize: fontSize, weight: weight)
        self.setTitleColor(color, for: .normal)
    }
}

你可能感兴趣的:(Swift抽取基类)