I am facing issue with UICollectionView
. I want all cell should have fixed size. But I cannot achieve requirement.
And what I am getting is like :
Here is my code :
private var totalColumns: Int = 3
private var cellSpace: CGFloat = 10.0
private var width: CGFloat {
var temp = (CGFloat(self.totalColumns - 1) * self.cellSpace)
temp = (self.collectionPreference?.frame.size.width ?? SCREEN_WIDTH) - temp
temp = temp / CGFloat(totalColumns)
return temp
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: width, height: width)
}
// func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
// return UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10)
// }
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return cellSpace
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return cellSpace
}
Before iOS 13
, I can achieve same UI with same code (and at that time I was searching that how can we design cell according to its content). And now in iOS 13
, I am struggling to achieve fixed size UI.... Very funny...
Can anyone have solution ?