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

  • rows: The number of rows in the masonry.
  • placementMode: The placement of subviews in the masonry.
  • horizontalSpacing: The distance between horizontally adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • verticalSpacing: The distance between vertically adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • content: A view builder that creates the content of this masonry.

VMasonry

A view that arranges its children in a vertical masonry.

Usage

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

Parameters

  • columns: The number of columns in the masonry.
  • placementMode: The placement of subviews in the masonry.
  • horizontalSpacing: The distance between horizontally adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • verticalSpacing: The distance between vertically adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • content: A view builder that creates the content of this masonry.

Masonry

A view that arranges its children in a masonry.

Usage

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

Parameters

  • axis: The layout axis of this masonry.
  • lines: The number of lines in the masonry.
  • placementMode: The placement of subviews in the masonry.
  • horizontalSpacing: The distance between horizontally adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • verticalSpacing: The distance between vertically adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • content: A view builder that creates the content of this masonry.

Requirements

  • iOS 14.0+, macOS 11.0+, tvOS 14.0+ or watchOS 7.0+
  • Xcode 12.0+

Installation

Contact

@ciaranrobrien on Twitter.

GitHub

View Github