-1

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!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
gmdev
  • 2,725
  • 2
  • 13
  • 28

2 Answers2

0

You can set collectionView sectionInset in this way:

private let spacing:CGFloat = 16.0

override func viewDidLoad() {
    super.viewDidLoad()

    let layout = UICollectionViewFlowLayout()
    layout.sectionInset = UIEdgeInsets(top: spacing, left: spacing, bottom: spacing, right: spacing)
    layout.minimumLineSpacing = spacing
    layout.minimumInteritemSpacing = spacing
    self.collectionView?.collectionViewLayout = layout
} 

Hope this will help you.

For more, you can see this: https://medium.com/@NickBabo/equally-spaced-uicollectionview-cells-6e60ce8d457b

Faysal Ahmed
  • 7,501
  • 5
  • 28
  • 50
0

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

Help
  • 84
  • 4