我正在尝试以编程方式创建 UICollectionView,并且我的单元格垂直堆叠而不是网格形式。
我的代码是:
let layout:UICollectionViewFlowLayout = UICollectionViewFlowLayout()
let screenSize: CGRect = UIScreen.main.bounds
let screenWidth = screenSize.width
let width = (screenWidth - 4)/3
layout.itemSize = CGSize(width: width, height: width+20)
layout.sectionInset = UIEdgeInsets(top:0,left:0,bottom:0,right:0)
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collectionView?.dataSource = self
collectionView?.delegate=self
collectionView?.collectionViewLayout = layout
collectionView?.register(NearbyCollectionViewCell.self, forCellWithReuseIdentifier: "cellId")
self.view.addSubview(collectionView!)