swift界面初体验

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)

注意事项:

  1. 超过一个元素必须要有父容器
  2. 容器必须给宽度(make.left.right.equalToSuperview()占整个宽度)
  3. 与自定义控件不能命名重合
    区分是否为自定义控件:淡蓝色是,紫色不是(系统自带)
    swift界面初体验_第1张图片
    swift界面初体验_第2张图片

你可能感兴趣的:(笔记,swift,开发语言,ios)