Skip to content

Instantly share code, notes, and snippets.

@balitax
Created April 4, 2020 04:32
Show Gist options
  • Save balitax/af523636f73b85a36d31db8b4a1e4ecb to your computer and use it in GitHub Desktop.
Save balitax/af523636f73b85a36d31db8b4a1e4ecb to your computer and use it in GitHub Desktop.
func layoutSection() -> NSCollectionLayoutSection {
var setWidthColumn: CGFloat = 0
var setHeight: CGFloat = 0
if column == 2 {
setWidthColumn = 0.5
setHeight = 0.75
} else if column == 3 {
setWidthColumn = 0.33
setHeight = 0.5
} else {
setWidthColumn = 0.5
setHeight = 0.75
}
let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(setWidthColumn),
heightDimension: .fractionalHeight(1.0))
let item = NSCollectionLayoutItem(layoutSize: itemSize)
item.contentInsets = NSDirectionalEdgeInsets(top: 4, leading: 4, bottom: 4, trailing: 4)
let groupSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
heightDimension: .fractionalWidth(setHeight))
let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize,
subitems: [item])
let section = NSCollectionLayoutSection(group: group)
section.contentInsets = NSDirectionalEdgeInsets(top: 18, leading: 0, bottom: 18, trailing: 0)
return section
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment