Sets the size and alignment of a view using width, height, and alignment parameters.
97.2% of iOS users can use this modifier
iOS 13+ required
.frame(width:height:alignment:) Sets fixed or flexible dimensions
width: CGFloat?height: CGFloat?alignment: Alignment.frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:) Sets flexible size constraints
minWidth: CGFloat?idealWidth: CGFloat?maxWidth: CGFloat?minHeight: CGFloat?idealHeight: CGFloat?maxHeight: CGFloat?alignment: AlignmentSet an exact width and height
Text("Hello")
.frame(width: 200, height: 100)Make view take maximum available width
Text("Hello")
.frame(maxWidth: .infinity)
.background(.blue)Set minimum and maximum dimensions
Text("Hello")
.frame(
minWidth: 100,
maxWidth: 300,
minHeight: 50,
maxHeight: 200
)Loading related modifiers...
The .frame() modifier requires iOS 13 or later. This means 97.2% of current iOS users can use this modifier.
Apply the .frame() modifier to any SwiftUI view. Check the code examples above for usage patterns.
Visit the official Apple documentation for detailed information.