Search code examples
iosswiftuicollectionviewuicollectionviewcelluicollectionviewlayout

Is there a way to add padding to a UICollectionView cell programmatically?


my UICollectionView UI

I would like to know how to add padding to cells within a collection view. In the image above, you can see that the shadow of the cell is being cut off where the table view ends(see black arrow).

I am fairly new to Swift programming, so a thorough explanation would be greatly appreciated.

Thanks!


Solution

  • Use this method - optional func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets