Skip to content

Instantly share code, notes, and snippets.

@hlung
Last active April 26, 2022 02:25
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hlung/a23b68b5730995759a6de9b45bd877f7 to your computer and use it in GitHub Desktop.
let layout = UICollectionViewCompositionalLayout(sectionProvider: {
(sectionIndex: Int, layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? in
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
// (1) setting widthDimension to half of collectionView size
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.5),
heightDimension: .absolute(50))
let group = NSCollectionLayoutGroup.horizontal(
layoutSize: groupSize,
subitem: item,
count: 1
)
// (2) customize layout group here
section.interGroupSpacing = 16
return section
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment