Skip to content

Instantly share code, notes, and snippets.

@dejanskledar
Last active May 10, 2018 07:22
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 dejanskledar/3a2374c2572207a95afdfc10c18a98e0 to your computer and use it in GitHub Desktop.
Save dejanskledar/3a2374c2572207a95afdfc10c18a98e0 to your computer and use it in GitHub Desktop.
This is a sample of a Centered CollectionView Flow Layout
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]? {
...
var rows = [CollectionViewRow]()
var currentRowY: CGFloat = -1
for attribute in attributes {
if currentRowY != attribute.frame.origin.y {
currentRowY = attribute.frame.origin.y
rows.append(CollectionViewRow(spacing: 10))
}
rows.last?.add(attribute: attribute)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment