Created
September 30, 2022 16:23
-
-
Save stevencurtis/fc2ce643e1eabde6a6cdd1ede049d801 to your computer and use it in GitHub Desktop.
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
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