Instance Method


Fixes this view at its ideal size.


func fixedSize() -> some View

Return Value

A view that fixes this view at its ideal size.


During the layout of the view hierarchy, each view proposes a size to each child view it contains. If the child view doesn’t need a fixed size it can accept and conform to the size offered by the parent.

For example, a Text view placed in an explicitly sized frame wraps and truncates its string to remain within its parent’s bounds:

Text("A single line of text, too long to fit in a box.")
    .frame(width: 200, height: 200)
A screenshot showing the text in a text view contained within its parent.

The fixedSize() modifier can be used to create a view that maintains the ideal size of its children both dimensions:

Text("A single line of text, too long to fit in a box.")
    .frame(width: 200, height: 200)

This can result in the view exceeding the parent’s bounds, which may or may not be the effect you want.

A screenshot showing a text view exceeding the bounds of its parent.

You can think of fixedSize() as the creation of a counter proposal to the view size proposed to a view by its parent. The ideal size of a view, and the specific effects of fixedSize() depends on the particular view and how you have configured it.

To create a view that fixes the view’s size in either the horizontal or vertical dimensions, see fixedSize(horizontal:vertical:).

See Also

Sizing a View

func frame(width: CGFloat?, height: CGFloat?, alignment: Alignment) -> View

Positions this view within an invisible frame with the specified size.

func fixedSize(horizontal: Bool, vertical: Bool) -> View

Fixes this view at its ideal size in the specified dimensions.

func layoutPriority(Double) -> View

Sets the priority by which a parent layout should apportion space to this child.