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
scaledToFill()scaleEffect(_:anchor:)scaleEffect(_:anchor:)scaleEffect(x:y:anchor:)scaleEffect(x:y:z:anchor:)aspectRatio(_:contentMode:)rotationEffect(_:anchor:)rotation3DEffect(_:axis:anchor:anchorZ:perspective:)perspectiveRotationEffect(_:axis:anchor:anchorZ:perspective:)rotation3DEffect(_:anchor:)rotation3DEffect(_:axis:anchor:)transformEffect(_:)transform3DEffect(_:)projectionEffect(_:)ProjectionTransform