正在尝试在swift生成布局
我正试图在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,
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]
}
}