passingnil
passingnil

Reputation: 413

How to set offset for the first element of UICollectionView

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

Upvotes: 0

Views: 5436

Answers (2)

Matthias
Matthias

Reputation: 1026

Put this in your ViewDidLoad:

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

I hope this helps

Upvotes: 12

passingnil
passingnil

Reputation: 413

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

Upvotes: 0

Related Questions