首页 > 解决方案 > 试图快速生成布局

问题描述

我正在尝试快速生成布局。它将动态生成。而且我添加了布局输出,但第三个框必须低于第二个框。第一个和第四个框必须保持不变。

import UIKit
class ViewController: UIViewController {
    var cellIds = ["1","2","3","4","5","6"]
    let cellSizes = [
        CGSize(width:190, height:300),
        CGSize(width:190, height:150),
        CGSize(width:190, height:150),
        CGSize(width:400, height:150),
        CGSize(width:190, height:100),
        CGSize(width:190, height:100),
        ]
     @IBOutlet weak var collectionView: UICollectionView!
     override func viewDidLoad() {
        super.viewDidLoad()
    }
}
extension ViewController: UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return cellIds.count
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "MenuCell", for: indexPath) as? UICustomCollectionViewCell
          cell!.layer.cornerRadius=10
          cell!.layer.masksToBounds=true
          return cell ?? UICollectionViewCell()
    }
}
extension ViewController: UICollectionViewDelegateFlowLayout {
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        return cellSizes[indexPath.item]
    }
}

布局

标签: swiftxcode

解决方案


推荐阅读