SwiftUI.cc
Snippets
LayoutLayout ModifiersBeginner

SwiftUI Frame, Padding, and Layout Priority

Control layout by combining flexible frames, padding, fixedSize, and layoutPriority rather than guessing with offsets.

5 min readUpdated 2026-06
Flexible row
import SwiftUI

struct MetricRow: View {
    let title: String
    let value: String

    var body: some View {
        HStack(spacing: 12) {
            Text(title)
                .lineLimit(2)
                .layoutPriority(1)

            Text(value)
                .font(.headline)
                .frame(minWidth: 72, alignment: .trailing)
        }
        .padding(12)
        .frame(maxWidth: .infinity, alignment: .leading)
    }
}
Use this when

A view should grow, shrink, or align within the space proposed by its parent.

Text truncates too early inside a horizontal layout.

Spacing should be stable across Dynamic Type sizes.

Avoid this when

You are trying to move a view visually without changing layout; offset may be the right tool.

The layout needs measurement from children; use preferences or a custom Layout.

Fixed dimensions would break localization or accessibility sizes.

Implementation notes

frame changes the proposal a view receives and the space it reports back to its parent.
padding increases the view's layout footprint; it is not just visual whitespace.
layoutPriority is best used sparingly to resolve a specific compression conflict.

Checklist

Preview long localized strings.

Prefer maxWidth: .infinity for flexible fill behavior.

Avoid fixed heights for text-heavy rows.

Related reference