Created
July 28, 2019 07:18
-
-
Save ppth0608/a7c538cb7f603b1bf127655eabfeda2e to your computer and use it in GitHub Desktop.
How to make square size of collection view cell
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
func collectionViewSize(flowLayout: UICollectionViewFlowLayout, numberOfItemsInRow count: Int) -> CGSize { | |
let itemSpacing = flowLayout.minimumInteritemSpacing | |
let leftInset = flowLayout.sectionInset.left | |
let rightInset = flowLayout.sectionInset.right | |
let size = (collectionView.bounds.width - (leftInset + rightInset) - (itemSpacing * CGFloat(count - 1))) / CGFloat(count) | |
return CGSize(width: size, height: size) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment