Skip to content
프로젝트

소개

SwiftUI layouts that arrange their subviews in a Pinterest-like grid.

웹 및 앱 개발

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

SwiftUI Masonry

SwiftUI layouts that arrange their subviews in a Pinterest-like grid.

Demo

VMasonry

A layout that arranges its subviews in a vertical masonry.

Usage

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

Parameters

  • columns: The number of columns in the masonry.
  • spacing: The distance between adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • placementMode: The placement mode for subviews in this masonry.

HMasonry

A layout that arranges its subviews in a horizontal masonry.

Usage

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

Parameters

  • rows: The number of rows in the masonry.
  • spacing: The distance between adjacent subviews, or nil if you want the masonry to choose a default distance for each pair of subviews.
  • placementMode: The placement mode for subviews in this masonry.

Advanced Usage

Layout

VMasonry and HMasonry both conform to SwiftUI's Layout protocol. Use AnyLayout to switch between VMasonry, HMasonry or any other layout at runtime.

Spacing & Placement

The placement of subviews can be controlled by using the placementMode parameter. Provide a MasonryPlacementMode case:

  • fill: Place each subview in the column/row with the most available space. This is the default behaviour.
  • order: Place each subview in view tree order.

The distance between adjacent subviews can be controlled by using the spacing or horizontalSpacing/verticalSpacing parameters.

VMasonry(columns: 2, spacing: 12, placementMode: .fill) {
    // Masonry content
}

// Or

VMasonry(columns: 2, horizontalSpacing: 8, verticalSpacing: 12, placementMode: .order) {
    // Masonry content
}

Columns & Rows

The masonryColumnSpan/masonryRowSpan view modifiers can be used to control the number of columns/rows a subview will span in a parent masonry layout. Subviews span 1 column/row by default.

The columns/rows masonry parameters and masonryColumnSpan/masonryRowSpan view modifiers can either be provided with an Int or with a MasonryColumnCount/MasonryRowCount:

  • adaptive: A variable number of columns/rows. This case uses the provided constraint to decide the exact number of columns/rows.
  • fixed: A constant number of columns/rows.
VMasonry(columns: .adaptive(minWidth: 128)) {
    // Other masonry content

    MyCellView()
        .masonryColumnSpan(.fixed(2))
    
    // Other masonry content
}

Requirements

  • iOS 16.0+, macOS 13.0+, tvOS 16.0+, visionOS 1.0+ or watchOS 9.0+
  • Xcode 26.0+

Installation

관련 프로젝트 살펴보기

불러오는 중…