UIView
Usage
class view: UIView {
var button = UIButton.init()
override init(frame: CGRect) {
super.init(frame: frame)
self.setupView()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
self.setupView()
}
// 初始化控件
func setupView() {
self.backgroundColor = UIColor.red
self.addSubview(self.button)
}
override func layoutSubviews() {
super.layoutSubviews()
// 这里更新子控件的 frame 或者添加约束
self.button.snp.makeConstraints { (make) in
make.width.equalTo(20)
}
}
}
// 使用
let anotherView = view.init()