.frame()

iOS 13+

Sets the size and alignment of a view using width, height, and alignment parameters.

Layout
Official Apple Documentation →
iOS User Coverage
97.2%
coverage

97.2% of iOS users can use this modifier

Version Compatibility
iOS 18.7
30.3% Supported
iOS 18.6
29.8% Supported
iOS 26.1
10.7% Supported
iOS 18.5
6.0% Supported
iOS 16.7
2.3% Supported
iOS 26.2
2.0% Supported
iOS 18.3
1.8% Supported
iOS 15.8
1.8% Supported
iOS 17.6
1.7% Supported
iOS 26.0
1.3% Supported

iOS 13+ required

Variants
.frame(width:height:alignment:)

Sets fixed or flexible dimensions

Parameters:
  • width: CGFloat?
  • height: CGFloat?
  • alignment: Alignment
.frame(minWidth:idealWidth:maxWidth:minHeight:idealHeight:maxHeight:alignment:)

Sets flexible size constraints

Parameters:
  • minWidth: CGFloat?
  • idealWidth: CGFloat?
  • maxWidth: CGFloat?
  • minHeight: CGFloat?
  • idealHeight: CGFloat?
  • maxHeight: CGFloat?
  • alignment: Alignment
Code Examples

Fixed Size

Set an exact width and height

Text("Hello")
    .frame(width: 200, height: 100)

Max Width

Make view take maximum available width

Text("Hello")
    .frame(maxWidth: .infinity)
    .background(.blue)

Flexible Size with Constraints

Set minimum and maximum dimensions

Text("Hello")
    .frame(
        minWidth: 100,
        maxWidth: 300,
        minHeight: 50,
        maxHeight: 200
    )

Loading related modifiers...

Frequently Asked Questions

What iOS version is required for .frame()?

The .frame() modifier requires iOS 13 or later. This means 97.2% of current iOS users can use this modifier.

How do I use .frame() in SwiftUI?

Apply the .frame() modifier to any SwiftUI view. Check the code examples above for usage patterns.

Where can I learn more?

Visit the official Apple documentation for detailed information.

Explore More SwiftUI Modifiers