Skip to content

Instantly share code, notes, and snippets.

@laevandus
Created January 19, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laevandus/ce4cc573ee21f56769e4901fa2feb65d to your computer and use it in GitHub Desktop.
Save laevandus/ce4cc573ee21f56769e4901fa2feb65d to your computer and use it in GitHub Desktop.
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
return itemLayoutAttributes
}
override func layoutAttributesForItem(at indexPath: IndexPath) -> UICollectionViewLayoutAttributes? {
let numberOfItems = collectionView?.numberOfItems(inSection: indexPath.section) ?? 0
guard numberOfItems > 0 else { return nil }
switch indexPath.section {
case 0:
return itemLayoutAttributes[indexPath.item]
default:
fatalError("Unknown section \(indexPath.section).")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment