I'm trying to do a UICollectionViewDelegateFlowLayout with 3 items to a row at a third of the screen width. For some reason it's adding spacing and not conforming to the square layout.
Here are the UICollectionViewDelegateFlowLayout functions.
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let yourWidth = (collectionView.bounds.width/3.0) - 2
let yourHeight = yourWidth
return CGSize(width: yourWidth, height: yourHeight)
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
//return UIEdgeInsets.zero
return UIEdgeInsets(top: 0,left: 0,bottom: 0,right: 0);
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 1
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 1
}
Please do not suggest adding a layout to a collection view in the viewDidLoad method. I tried that and it didn't work because it deletes my header.