explaingit

chiahsien/chtcollectionviewwaterfalllayout

4,616Objective-CAudience · developerComplexity · 2/5Setup · easy

TLDR

An iOS and tvOS library that adds a Pinterest-style waterfall grid layout to UICollectionView, displaying items in multiple columns where each item's height matches its own content so columns end at different positions.

Mindmap

mindmap
  root((Waterfall Layout))
    What it does
      Pinterest style grid
      Variable height items
      Multi column layout
    Customization
      Column count
      Item spacing
      Section insets
      Fill order
    Integration
      Swift Package Manager
      CocoaPods
      Manual copy
    Requirements
      iOS 13 minimum
      Xcode 15 for SPM
    Audience
      iOS developers
      tvOS developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add a Pinterest-style waterfall grid to any iOS app using UICollectionView with minimal API changes from the standard flow layout

USE CASE 2

Display a photo feed or card list where items have varying heights arranged across multiple columns

USE CASE 3

Customize column count, spacing, header/footer heights, and fill order independently per section in the same collection view

USE CASE 4

Migrate from UICollectionViewFlowLayout to a waterfall layout using a familiar delegate pattern

Tech stack

Objective-CSwiftSwift Package ManagerCocoaPodsiOStvOS

Getting it running

Difficulty · easy Time to first run · 30min

Requires iOS 13 or tvOS 13 minimum, Swift Package Manager integration requires Xcode 15 or later. Version 1.0.0 has breaking API changes from 0.9.x documented in the README.

License type is not specified in the explanation.

In plain English

CHTCollectionViewWaterfallLayout is an iOS and tvOS library that adds a Pinterest-style waterfall grid layout to UICollectionView, which is Apple's standard way of displaying scrollable grids and lists in mobile apps. A waterfall layout arranges items in multiple columns where each item takes up a height proportional to its own content, so columns can end at different vertical positions rather than staying perfectly even. This creates the staggered, dynamic look associated with apps like Pinterest. The library is designed to feel similar to UICollectionViewFlowLayout, which is the built-in grid layout Apple provides. The goal is that iOS developers who already know how to use the standard layout can adopt this one without learning a completely different API. The README says the library is highly customizable and handles performance well even with large numbers of items, citing 10,000 or more items as a benchmark for smooth scrolling. Customization is done through properties set on the layout object and through an optional delegate protocol implemented by the view controller. Configurable options include the number of columns, spacing between columns and items, section insets, header and footer heights and insets, and the order in which items fill the columns (left-to-right, right-to-left, or shortest-column-first). Different sections in the same collection view can use different column counts. The library can be added to a project through Swift Package Manager (the recommended approach), CocoaPods, or by copying the source files directly. Both Swift and Objective-C implementations are included, and demo projects for both languages are in the repository. The minimum supported platform is iOS 13 or tvOS 13, and Swift Package Manager requires Xcode 15 or later. Version 1.0.0 was a full rewrite of the Swift implementation and includes several breaking changes from 0.9.x, which the README documents in detail.

Copy-paste prompts

Prompt 1
Show me how to add CHTCollectionViewWaterfallLayout to an iOS project via Swift Package Manager and set up a 3-column waterfall grid in Swift
Prompt 2
How do I implement the CHTCollectionViewDelegateWaterfallLayout protocol in Swift to return different heights for each item in a photo feed?
Prompt 3
Write a UICollectionViewController in Swift that uses CHTCollectionViewWaterfallLayout to display cards with variable heights in 2 columns
Prompt 4
How do I configure CHTCollectionViewWaterfallLayout to fill columns in shortest-column-first order instead of left-to-right?
Prompt 5
What are the breaking changes between CHTCollectionViewWaterfallLayout 0.9.x and 1.0.0 that I need to update in my Swift code?
Open on GitHub → Explain another repo

← chiahsien on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.