Instance Method

fixedSize()

Fixes the view at its ideal size.

Declaration

func fixedSize() -> some View

Return Value

A view that fixes this view at its ideal size in the dimensions given in fixedDimensions.

Discussion

This example shows the effect of fixedSize() 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()
.frame(width: 200, height: 200)
.border(Color.gray)

Without the call to fixedSize(), 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)

See Also

Sizing a View

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

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

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

Fixes the 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 the child.