0

I want to set offset offset for the first element of collectionView, so the first cell will apear in the center of the collectionView. See photo

passingnil
  • 403
  • 1
  • 5
  • 14

2 Answers2

12

Put this in your ViewDidLoad:

yourCollectionView.contentInset = UIEdgeInsets(top: 0, left: yourCollectionView.frame.width/2, bottom: 0, right: 0)

I hope this helps

Neeraj Joshi
  • 721
  • 9
  • 26
Matthias
  • 999
  • 11
  • 25
  • This sets the inset for every cell of the collection view though. How do we get it to do it for the first cell only? Thanks – Supertecnoboff Nov 13 '20 at 21:54
0

I did it with UIEdgeInsets. It can be set either in interface builder or in code by setting sectionInsets property of UICollectionViewFlowLayout

passingnil
  • 403
  • 1
  • 5
  • 14