Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yfujiki/8c29a0fbfe27650cc9f4da2b79599f1e to your computer and use it in GitHub Desktop.
Save yfujiki/8c29a0fbfe27650cc9f4da2b79599f1e to your computer and use it in GitHub Desktop.
func setupCatFoodsSection() -> NSCollectionLayoutSection {
// 1. Configuring Section Layout. Item -> Group -> Section
// Item
let item = NSCollectionLayoutItem(
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalHeight(0.5)))
item.contentInsets = NSDirectionalEdgeInsets(top: 4.0,
leading: 0.0,
bottom: 4.0,
trailing: 0.0)
// Group
let group = NSCollectionLayoutGroup.vertical(
layoutSize: NSCollectionLayoutSize(widthDimension: .fractionalWidth(0.5),
heightDimension: .absolute(240)),
subitem: item,
count: 2)
// Section
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 16.0,
leading: 0.0,
bottom: 16.0,
trailing: 0.0)
// 2. Horizontal Scroll
section.orthogonalScrollingBehavior = .groupPaging
// 3. Header
section.boundarySupplementaryItems = [headerViewSupplementaryItem]
return section
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment