Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在尝试在swift生成布局_Swift_Xcode - Fatal编程技术网

正在尝试在swift生成布局

正在尝试在swift生成布局,swift,xcode,Swift,Xcode,我正试图在swift生成一个布局。它将动态生成。我已经添加了布局输出,但第三个框必须在第二个框的下方。第一个和第四个框必须保持不变 import UIKit class ViewController: UIViewController { var cellIds = ["1","2","3","4","5","6"] let cellSizes = [ CGSize(width:190, height:300), CGSize(width:190,

我正试图在swift生成一个布局。它将动态生成。我已经添加了布局输出,但第三个框必须在第二个框的下方。第一个和第四个框必须保持不变

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]
    }
}