SwiftUI Field Guidebeta

Fixed Frames

A fixed frame lets us specify an optional width and height (as opposed to a flexible frame, which lets us specify upper and lower bounds). The behavior of a fixed frame only has a few rules: If we specify a non-nil dimension, that value is proposed to the child (regardless of the value proposed to the frame). Likewise, the frame reports that dimension as its value, disregarding the value of the child.

In the example below, we can see that the text is always wrapped inside its frame. The frame has a constant size, regardless of what's proposed.

Code
Text("Hello, world")    .frame(width: 
, height: 100)
/* .border(Color.red) */
Preview
200

We can also specify an alignment parameter. The default is .center. Note that the alignment parameter also works when the frame is smaller than its content.

Code
Text("Hello, world")    .fixedSize()    .frame(width: 150, height: 100)    .border(Color.red)
Preview
leadingcentertrailing
topcenterbottom