Contents

scaledToFit()

Scales this view to fit its parent.

Declaration

nonisolated func scaledToFit() -> some View

Return Value

A view that scales this view to fit its parent, maintaining this view’s aspect ratio.

Discussion

Use scaledToFit() to scale this view to fit its parent, while maintaining the view’s aspect ratio as the view scales.

Circle()
    .fill(Color.pink)
    .scaledToFit()
    .frame(width: 300, height: 150)
    .border(Color(white: 0.75))

[Image]

This method is equivalent to calling aspectRatio(_:contentMode:) with a nil aspectRatio and a content mode of ContentMode.fit.

See Also

Scaling, rotating, or transforming a view