Frage

I am working on an iOS app that has a UICollectionView. I would like to make a simple custom layout in which the middle cell on each row is slightly lower than the one on the right and left. I've been looking over tutorials and the apple documentation but most of it is for a much more complicated set up.

Is there is a quick way to stagger the middle cell. Thanks for any input!

Currently the collectionView looks like this...

Collection View Screen Shot

I simply want the center cells shifted down by 40 pixels or so.

War es hilfreich?

Lösung

Subclass UICollectionViewFlowLayout and alter the response that the superclass gives so that the cells are positioned where you want them.

Here's an example of a UICollectionViewFlowLayout subclass:

https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch08p466collectionViewFlowLayout2/ch21p748collectionViewFlowLayout2/MyFlowLayout.swift

It shifts the cells left (so that they are left-justified instead of full-justified across the screen). It is not difficult to see how to adapt this to shift certain cells down.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top