user5907771
user5907771

Reputation:

Set position of first and last UICollectionViewCell at centre of UICollectionView

I have a requirement in which the collection view should start at the centre of the screen and when I start scrolling, it should scroll to the left end. Also the last cell should scroll to the centre. If it is confusing please refer the images: My Current state:

My Current State

What I want at initial stage:

InitialStage

Also at the end of scrolling:

End of scrolling

I played with content offset a little but no success so far

Upvotes: 1

Views: 584

Answers (1)

Fogmeister
Fogmeister

Reputation: 77621

The content offset is the amount that the collection view (or actually the scroll view behind it) is currently scrolled.

What you are looking for is the contentInset.

You should be able to change this through the UICollectionViewLayout object that you are using. If you are using a UICollectionViewFlowLayout then it has a property for sectionInset.

If you do something like...

layout.sectionInset = UIEdgeInsets(top: 0, left: screenWidth * 0.5, bottom: 0, right: screenWidth * 0.5)

It should get you something like what you are looking for.

Upvotes: 1

Related Questions