I know the documented advice is to use UICollectionViewFlowLayout if you are doing anything "like a grid or a line-based breaking layout". However, I am not sure this is true for my case.
I want a grid but do not want a line-breaking layout. Items should be laid out infinitely both horizontally and vertically without ever stacking. Essentially, a giant chessboard that scrolls horizontally or vertically if content goes beyond the frame.
To subclass UICollectionViewFlowLayout I would have to:
- Override
prepareLayout
to stop the layout from wrapping items. This seems like a lot of work. - Override
collectionViewContentSize
.
Apple says they have done "lots of hard work" in crafting UICollectionViewFlowLayout, so I should leverage it if I can. But if I have to override prepareLayout
to turn off line-breaking, I suspect that I am throwing away a large part of their work. Of their work that is left, I probably will not use most of it anyway (for example, minimumLineSpacingForSectionAtIndex
).
Because the layout I want is so simple, I suspect that I should subclass UICollectionViewLayout instead, because:
- I will have a simpler and cleaner implementation with everything in one layout class instead of spread between a subclass and a delegate.
- I don't think it will be that much harder than subclassing UICollectionViewFlowLayout because I have to override
prepareLayout
in both cases, and I suspect that is where all the hard work will be. - I'll be in a better position to tweak other UICollectionViewLayoutAttributes in custom ways than trying to add another kludge on top of a UICollectionViewFlowLayout subclass.
Is my conclusion correct?