History
Loading...
Loading...
September 1, 2025
GeometryReader with .frame(maxWidth: .infinity, maxHeight: .infinity) and .clipped() to create responsive layouts that adapt to container changes while preventing content overflow during device rotation or dynamic type scaling.This pattern uses GeometryReader to create proportional sizing based on available space, making UI elements scale appropriately across different screen sizes and orientations. All spacing, fonts, and padding are calculated as percentages of the container width.
struct AdaptiveCard: View {
var body: some View {
GeometryReader { geometry in
VStack(spacing: geometry.size.width * 0.02) {
Image(systemName: "star.fill")
.font(.system(size: geometry.size.width * 0.1))
Text("Adaptive Content")
.font(.system(size: geometry.size.width * 0.04))
.multilineTextAlignment(.center)
.padding(.horizontal, geometry.size.width * 0.05)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
}
.aspectRatio(1.5, contentMode: .fit)
.background(Color.blue.opacity(0.1))
.cornerRadius(12)
}
}Proportional layouts eliminate hard-coded values that break on different devices. By using geometry-relative sizing, your UI maintains visual consistency and readability across iPhone SE to iPad Pro, while automatically adapting to accessibility settings like Dynamic Type.