Customizing the Layout

The display of cells is not driven by the collection view itself but by the collection view’s layout. The layout object is responsible for the placement of cells onscreen. Layouts, in turn, are driven by a subclass of UICollectionViewLayout.

The flow layout that Photorama is currently using is UICollectionViewFlowLayout, which is the only concrete UICollectionViewLayout subclass provided by the UIKit framework.

Some of the properties you can customize on UICollectionViewFlowLayout are:

  • scrollDirection – Do you want to scroll vertically or horizontally?

  • minimumLineSpacing – What is the minimum spacing between lines?

  • minimumInteritemSpacing – What is the minimum spacing between items in a row (or column, if scrolling horizontally)?

  • itemSize – What is the size of each item?

  • sectionInset – What are the margins used to lay out content for each section?

Figure 21.6 shows how these properties affect the presentation of cells using UICollectionViewFlowLayout.

Figure 21.6  UICollectionViewFlowLayout properties

Figure shows the UICollectionViewFlowLayout properties.

Open Main.storyboard and select the collection view. Open the size inspector and configure the Cell Size, Min Spacing, and Section Insets as shown in Figure 21.7.

Figure 21.7  Collection view size inspector

Screenshot shows the Collection view size inspector.

Build and run the application to see how the layout has changed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset