Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created September 30, 2022 16:23
Show Gist options
  • Save stevencurtis/fc2ce643e1eabde6a6cdd1ede049d801 to your computer and use it in GitHub Desktop.
Save stevencurtis/fc2ce643e1eabde6a6cdd1ede049d801 to your computer and use it in GitHub Desktop.
extension BasicFlowLayoutViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return UIEdgeInsets(top: 0, left: 15, bottom: 100, right: 15)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let noOfCellsInRow = 2
let flowLayout = collectionViewLayout as! UICollectionViewFlowLayout
let totalSpace = flowLayout.sectionInset.left
+ flowLayout.sectionInset.right
+ (flowLayout.minimumInteritemSpacing * CGFloat(noOfCellsInRow - 1))
let size = Int((collectionView.bounds.width - totalSpace) / CGFloat(noOfCellsInRow)) - 20
return CGSize(width: size, height: size)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment