5.3. Providing a Flow Layout to a Collection View
Problem
You want to provide a grid-like layout to your collection view so that your content can render in a way similar to that shown in Figure 5-1.
Solution
Create an instance of the UICollectionViewFlowLayout class, instantiate
your collection view controller using the initWithCollectionViewLayout: designated
initializer of the UICollectionViewController class, and pass
your layout object to this method.
Discussion
A flow layout can easily be instantiated, but before it can be
passed to a collection view, it has to be configured. Here we are going
to discuss the various properties that you can tweak on an instance of
the UICollectionViewFlowLayout class
and how they can affect the rendering of your collection view
cells:
minimumLineSpacingA floating point value that dictates to the flow layout the minimum number of points it has to reserve between each row. The layout object may decide to allocate more space in order to make the layout look good, but it must not allocate less. If your collection view is too small for the items to fit into it, your items will be clipped, just like any other view in the iOS SDK.
minimumInteritemSpacingA floating point value to indicate the minimum number of points that the layout should reserve between cells on the same row. Again, this is the minimum number of points, and the layout, depending on the size of the collection view, may decide to increase this number.
itemSizeA
CGSizethat specifies the size ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access