Instance Method

scaledToFill()

Scales this view to fill its parent.

Declaration

func scaledToFill() -> some View

Return Value

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

Discussion

This view’s aspect ratio is maintained as the view scales. This method is equivalent to calling aspectRatio(nil, contentMode: .fill).

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

See Also

Scaling Views

func scaledToFit() -> View

Scales this view to fit its parent.

Beta
func aspectRatio(CGFloat?, contentMode: ContentMode) -> View

Constrains this view’s dimensions to the specified aspect ratio.

Beta
func aspectRatio(CGSize, contentMode: ContentMode) -> View

Constrains this view’s dimensions to the aspect ratio of the given size.

Beta
func imageScale(Image.Scale) -> View

Set the image scale within self.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software