Skip to content

Instantly share code, notes, and snippets.

@qzda
qzda / MasonryLayout.swift
Created February 4, 2026 14:26
Swift UI Masonry Layout
import SwiftUI
struct MasonryLayout: Layout {
let columns: Int
let spacing: CGFloat
func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
let width = proposal.width ?? 0
let columnWidth = (width - spacing * CGFloat(columns - 1)) / CGFloat(columns)