通过数组使用snpkit快速约束

        var viewHeights[CGFloat]?
        var viewOffsetYs[CGFloat]?
        var views: [UIView]?
        var lastView: UIView? = nil
        
        for (index, view) in views.enumerated() {
            
            let height = viewHeights[index]
            let offsetY = viewOffsetYs[index]
            self.view.addSubview(view)
            
            view.snp.makeConstraints { (make) in
                make.leading.equalToSuperview().offset(10)
                make.trailing.equalToSuperview().offset(-10)
                make.height.equalTo(height)
                make.top.equalTo(lastView?.snp.bottom ?? self.view).offset(offsetY)
            }
            
            lastView = view
        }

你可能感兴趣的:(通过数组使用snpkit快速约束)