Skip to content

Instantly share code, notes, and snippets.

@KrauserHuang
Created April 1, 2022 08:30
Show Gist options
  • Save KrauserHuang/0cfa15a8d993404154c7ec29afa6de84 to your computer and use it in GitHub Desktop.
Save KrauserHuang/0cfa15a8d993404154c7ec29afa6de84 to your computer and use it in GitHub Desktop.
func generateLayout() -> UICollectionViewLayout {
let itemSize = NSCollectionLayoutSize(
widthDimension = .fractionalWidth(1.0),
heightDimension = .fractionalHeight(1.0))
let fullPhotoItem = NSCollectionLayoutItem(layoutSize: itemSize)
fullPhotoItem.contentInsets = NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2)
let groupSize = NSCollectionLayoutSize(
widthDimension = .fractionalWidth(1.0),
heightDimension = .fractionalWidth(1/3))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize,
subitem: fullPhotoItem,
count: 2)
let section = NSCollectionLayoutSection(group: group)
let layout = UICollectionViewCompositionalLayout(section: section)
return layout
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment