ciaranrobrien / SwiftUIMasonry

SwiftUI views that arrange their children in a Pinterest-like layout.
MIT License
162 stars 12 forks source link

SwiftUI Masonry

SwiftUI views that arrange their children in a Pinterest-like layout.

Demo

HMasonry

A view that arranges its children in a horizontal masonry.

Usage

ScrollView(.horizontal) {
    HMasonry(rows: 2) {
        //Masonry content
    }
}

Parameters

VMasonry

A view that arranges its children in a vertical masonry.

Usage

ScrollView(.vertical) {
    VMasonry(columns: 2) {
        //Masonry content
    }
}

Parameters

Masonry

A view that arranges its children in a masonry.

Usage

ScrollView(.vertical) {
    Masonry(.vertical, lines: 2) {
        //Masonry content
    }
}

Parameters

Advanced Usage

The distance between adjacent subviews can be controlled in both axes, by using the horizontalSpacing and verticalSpacing parameters instead of the spacing parameter.

The lines, columns and rows parameters can be initialised with one of the MasonryLines cases:

Masonry views can be initialised with a data source using the data and id parameters, where content builds each child view dynamically from the data source. Using these initialisers also provides access to the lineSpan, columnSpan and rowSpan parameters; return an Int or a MasonryLines case to set the number of lines a child view will span across.

The masonryPlacementMode view modifier can be used to control how masonry views place their children. Provide a MasonryPlacementMode case:

Requirements

Installation

Contact

@ciaranrobrien on Twitter.