swift snp布局

swift snp布局_第1张图片
123.png
 func setupUI()  {
        
        
      
        let grayView = UIView()
        grayView.backgroundColor = UIColor.gray
        self.addSubview(grayView)
        grayView.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(5)
           
            make.left.equalTo(self).offset(8)
            make.bottom.equalTo(self).offset(-20)
             make.width.equalTo(5)
        }
        
        
        let taskNameL = UILabel()
        taskNameL.text = "恒泰开户"
        taskNameL.font = UIFont.systemFont(ofSize: 14)
        self.addSubview(taskNameL)
        taskNameL.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(5)
            make.left.equalTo(self).offset(20)
            make.width.equalTo(100)
            make.height.equalTo(70)
        }
        
        
        let priceL = UILabel()
        priceL.text = "¥ 20"
        priceL.font = UIFont.systemFont(ofSize: 20)
        self.addSubview(priceL)
        priceL.snp.makeConstraints { (make) in
            make.top.equalTo(self).offset(50)
            make.left.equalTo(self).offset(20)
            make.width.equalTo(100)
            make.height.equalTo(70)
        }
        
        
        let dateL = UILabel()
        dateL.text = "2017.09.13 - 2017.03.30"
        dateL.font = UIFont.systemFont(ofSize: 14)
        self.addSubview(dateL)
        dateL.snp.makeConstraints { (make) in
            make.bottom.equalTo(self).offset(-15)
            make.left.equalTo(self).offset(20)
            make.width.equalTo(300)
            make.height.equalTo(15)
        }
        
        

        let button:UIButton = UIButton(type:.custom)
        button.setTitle("查看详情>>", for:.normal) //普通状态下的文字
        button.titleLabel?.font = UIFont.systemFont(ofSize: 11)
        button.setTitleColor(UIColor.blue, for: .normal) //普通状态下文字的颜色
        button.addTarget(self, action: #selector(push), for: .touchUpInside)
        self.addSubview(button)
        button.snp.makeConstraints { (make) in
            make.bottom.equalTo(self).offset(-15)
            make.right.equalTo(self).offset(-20)
            make.width.equalTo(100)
            make.height.equalTo(40)
        }
    }

你可能感兴趣的:(swift snp布局)