1.添加视图
lazy var contentView: UIView = {
let a = UIView()
self.view.addSubview(a)
return a
}()
2.添加文本
lazy var tipsLabel: UILabel = {
let a = UILabel()
a.font = UIFont.regular13
a.textColor = UIColor.withHex(hexString:"#58C65C")
a.text = R.string.localizable.off_site_sharing_poster_slogin.fm
contentView.addSubview(a)
return a
}()
3添加图片
lazy var logoIcon: UIImageView = {
let a = UIImageView(image: R.image.share.logo())
contentView.addSubview(a)
return a
}()
4.调整宽高,位置
override func configUI() {
super.configUI()
self.logoIcon.snp.makeConstraints { make in
make.width.height.equalTo(18)
make.left.equalTo(20)
make.top.equalTo(logoIcon.snp.bottom).offset(5)
}
}
5.水平居中
make.left.right.equalToSuperview()
make.centerX.equalToSuperview()
6.设置颜色透明度
UIColor.withHex(hexString:"#71DA75").withAlphaComponent(0.19)
注意事项:
- 超过一个元素必须要有父容器
- 容器必须给宽度(make.left.right.equalToSuperview()占整个宽度)
- 与自定义控件不能命名重合
区分是否为自定义控件:淡蓝色是,紫色不是(系统自带)