Соответствует протоколу UICollectionViewDelegateFlowLayout и реализует этот метод.Вам просто нужно манипулировать возвращаемыми значениями так, как вы хотите для своих ячеек коллекции.
// This method will create collectionView cell size. Delegate method of UICollectionViewDelegateFlowLayout.
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 200.0, height: 200.0)
}
// This method will create horizontal padding between two cells. Delegate method of UICollectionViewDelegateFlowLayout.
func collectionView(_ collectionView: UICollectionView,
layout collectionViewLayout: UICollectionViewLayout,
minimumInteritemSpacingForSectionAt section: Int) -> CGFloat {
return 5.0
}
// This method will create vertical padding between upper cell and lower cell. Delegate method of UICollectionViewDelegateFlowLayout.
func collectionView(_ collectionView: UICollectionView, layout
collectionViewLayout: UICollectionViewLayout,
minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return 10.0
}