I want to set offset offset for the first element of collectionView, so the first cell will apear in the center of the collectionView.
Asked
Active
Viewed 5,156 times
0

passingnil
- 403
- 1
- 5
- 14
-
And what you've tried so far? – E-Riddie Nov 14 '16 at 15:10
-
1You can try to set the `contentOffset` of your `UICollectionView`, to `(yourCollectionView.width-firstElement.widh)/2.` on the y. – Larme Nov 14 '16 at 15:11
2 Answers
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