美文网首页
Swift抽取基类

Swift抽取基类

作者: wu890608 | 来源:发表于2018-12-10 19:22 被阅读0次

    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抽取基类

          本文链接:https://www.haomeiwen.com/subject/kjvdhqtx.html