Last active
May 10, 2018 07:22
-
-
Save dejanskledar/3a2374c2572207a95afdfc10c18a98e0 to your computer and use it in GitHub Desktop.
This is a sample of a Centered CollectionView Flow Layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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