Recipe: Scrolling Horizontal Lists

Collection views offer the ability to create horizontal scrolling lists, a counterpoint to table views that only scroll vertically. To accomplish this, you need to take a few things into account, primarily that flow layouts in their default state naturally wrap their sections. Consider Figure 10-5. It shows two collection views, both of which scroll horizontally. The top image consists of a single section with 100 items; the bottom has 100 sections of a single item each.

Image

Figure 10-5 Top: A single section with 100 items. Bottom: 100 sections with a single item each.

You could force the top layout not to wrap ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.