Contents

scaledToFill()

Scales this view to fill its parent.

Declaration

nonisolated func scaledToFill() -> some View

Return Value

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

Discussion

Use scaledToFill() to scale this view to fill its parent, while maintaining the view’s aspect ratio as the view scales:

Circle()
    .fill(Color.pink)
    .scaledToFill()
    .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.fill.

See Also

Scaling, rotating, or transforming a view