Instance Method

fixedSize(horizontal:vertical:)

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

Declaration

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

Parameters

horizontal

A Boolean value indicating whether to fix the width of the view.

vertical

A Boolean value indicating whether to fix the height of the view.

Return Value

A view that fixes this view at its ideal size in the dimensions specified by horizontal and vertical.

Discussion

This example shows the effect of fixedSize(horizontal:vertical:) on a text view that is wider than its parent, preserving the ideal, untruncated width of the text view.

Text("A single line of text, too long to fit in a box.")
.fixedSize(horizontal: true, vertical: false)
.frame(width: 200, height: 200)
.border(Color.gray)

Without the call to fixedSize(horizontal:vertical:), the text view has its width set by its parent, which truncates the line of text.

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