I have a UICollectionView with the following layout:
private func createCollectionViewLayout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.49), heightDimension: .estimated(150))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
//item.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: NSCollectionLayoutSpacing.flexible(2), top: NSCollectionLayoutSpacing.flexible(2), trailing: NSCollectionLayoutSpacing.flexible(2), bottom: NSCollectionLayoutSpacing.flexible(2))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1), heightDimension: .estimated(1)),
subitems: [item])
group.interItemSpacing = NSCollectionLayoutSpacing.flexible(0)
group.edgeSpacing = NSCollectionLayoutEdgeSpacing(leading: NSCollectionLayoutSpacing.flexible(5), top: NSCollectionLayoutSpacing.flexible(5), trailing: NSCollectionLayoutSpacing.flexible(5), bottom: NSCollectionLayoutSpacing.flexible(5))
let section = NSCollectionLayoutSection(group: group)
return UICollectionViewCompositionalLayout(section: section)
}
It works pretty well except that it doesn't fit cells together vertically. i.e. in the image below, I want the 'Spaghetti Carbonara' cell to come directly below the 'Cuban Ropa Vieja' cell. Any idea how I can achieve this?