Skip to content

Instantly share code, notes, and snippets.

@ppth0608
Created July 28, 2019 07:18
Show Gist options
  • Save ppth0608/a7c538cb7f603b1bf127655eabfeda2e to your computer and use it in GitHub Desktop.
Save ppth0608/a7c538cb7f603b1bf127655eabfeda2e to your computer and use it in GitHub Desktop.
How to make square size of collection view cell
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