Created
October 11, 2017 07:08
-
-
Save rafattouqir/bd61acc9e2d1cc7e15557d5efb69fb22 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 CustomCollectionViewController: UICollectionViewDelegateFlowLayout { | |
fileprivate var sectionInsets: UIEdgeInsets { return .zero } | |
fileprivate var itemsPerRow: CGFloat { return 3 } | |
fileprivate var interitemSpace: CGFloat { return 10 } | |
func collectionView(_ collectionView: UICollectionView, | |
layout collectionViewLayout: UICollectionViewLayout, | |
sizeForItemAt indexPath: IndexPath) -> CGSize { | |
let sectionPadding = sectionInsets.left * (itemsPerRow + 1) // sectionInsets.left = sectionsInsets.right | |
let interitemPadding = max(0.0, itemsPerRow - 1) * interitemSpace | |
let availableWidth = collectionView.bounds.width - sectionPadding - interitemPadding | |
let widthPerItem = availableWidth / itemsPerRow | |
return CGSize(width: widthPerItem, height: widthPerItem) | |
} | |
func collectionView(_ collectionView: UICollectionView, | |
layout collectionViewLayout: UICollectionViewLayout, | |
insetForSectionAt section: Int) -> UIEdgeInsets { | |
return sectionInsets | |
} | |
func collectionView(_ collectionView: UICollectionView, | |
layout collectionViewLayout: UICollectionViewLayout, | |
minimumLineSpacingForSectionAt section: Int) -> CGFloat { | |
return 0.0 | |
} | |
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { | |
return interitemSpace | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment