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)
}
}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
SwiftUI Overlay, Background, and zIndex
Layer views deliberately with background, overlay, and zIndex while keeping the base layout stable.
SwiftUI Alignment Guides and Coordinate Space
Reach for alignment guides and coordinate spaces when default stack alignment is not expressive enough.
SwiftUI PreferenceKey for Layout Measurement
Pass child measurements up the view tree with PreferenceKey when a parent needs information children know first.