SnapKit之multipliedBy使用

2021-08-18  本文已影响0人  梁森的简书

multipliedBy意思

乘以

需求

某个View(该view的宽度是不确定的)上横向有两个子View,要求:

  1. 两个子View的间距是10
  2. 左侧子View的宽度和右侧子View宽度比是2:1
  3. 左侧子View的宽高比是2:1
  4. 左侧子View的左、上、下和其父View对齐
  5. 右侧子View的右、上、下和其父View对齐

效果图

0.multiplied.jpg

实现代码

        // 父view
        let superView = UIView()
        superView.backgroundColor = .yellow
        view.addSubview(superView)
        superView.snp.makeConstraints { make in
            make.left.right.equalToSuperview()
            make.top.equalToSuperview().offset(100)
        }
        // 左侧子view
        let leftView = UIView()
        leftView.backgroundColor = .red
        superView.addSubview(leftView)
        leftView.snp.makeConstraints { make in
            make.left.top.bottom.equalToSuperview()
            make.height.equalTo(leftView.snp.width).multipliedBy(1.0/2.0)
        }
        // 右侧子view
        let rightView = UIView()
        rightView.backgroundColor = .red
        superView.addSubview(rightView)
        rightView.snp.makeConstraints { make in
            make.right.top.bottom.equalToSuperview()
            make.left.equalTo(leftView.snp.right).offset(10)
            make.width.equalTo(leftView.snp.width).multipliedBy(1.0/2.0)
        }
上一篇 下一篇

猜你喜欢

热点阅读