---
title: "aspectRatio(_:contentMode:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/aspectratio(_:contentmode:)"
---

# aspectRatio(_:contentMode:)

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

## Declaration

```swift
nonisolated func aspectRatio(_ aspectRatio: CGFloat? = nil, contentMode: ContentMode) -> some View

```

## Parameters

- `aspectRatio`: The ratio of width to height to use for the resulting view. Use nil to maintain the current aspect ratio in the resulting view.
- `contentMode`: A flag that indicates whether this view fits or fills the parent context.

## Mentioned in

Fitting images into available space

## Return Value

Return Value A view that constrains this view’s dimensions to the aspect ratio of the given size using contentMode as its scaling algorithm.

## Discussion

Discussion Use aspectRatio(_:contentMode:) to constrain a view’s dimensions to an aspect ratio specified by a CGFloat using the specified content mode. If this view is resizable, the resulting view will have aspectRatio as its aspect ratio. In this example, the purple ellipse has a 3:4 width-to-height ratio, and scales to fit its frame: Ellipse()     .fill(Color.purple)     .aspectRatio(0.75, contentMode: .fit)     .frame(width: 200, height: 200)     .border(Color(white: 0.75))

## See Also

### Scaling, rotating, or transforming a view

- [scaledToFill()](swiftui/view/scaledtofill().md)
- [scaledToFit()](swiftui/view/scaledtofit().md)
- [scaleEffect(_:anchor:)](swiftui/view/scaleeffect(_:anchor:).md)
- [scaleEffect(_:anchor:)](swiftui/view/scaleeffect(_:anchor:).md)
- [scaleEffect(x:y:anchor:)](swiftui/view/scaleeffect(x:y:anchor:).md)
- [scaleEffect(x:y:z:anchor:)](swiftui/view/scaleeffect(x:y:z:anchor:).md)
- [rotationEffect(_:anchor:)](swiftui/view/rotationeffect(_:anchor:).md)
- [rotation3DEffect(_:axis:anchor:anchorZ:perspective:)](swiftui/view/rotation3deffect(_:axis:anchor:anchorz:perspective:).md)
- [perspectiveRotationEffect(_:axis:anchor:anchorZ:perspective:)](swiftui/view/perspectiverotationeffect(_:axis:anchor:anchorz:perspective:).md)
- [rotation3DEffect(_:anchor:)](swiftui/view/rotation3deffect(_:anchor:).md)
- [rotation3DEffect(_:axis:anchor:)](swiftui/view/rotation3deffect(_:axis:anchor:).md)
- [transformEffect(_:)](swiftui/view/transformeffect(_:).md)
- [transform3DEffect(_:)](swiftui/view/transform3deffect(_:).md)
- [projectionEffect(_:)](swiftui/view/projectioneffect(_:).md)
- [ProjectionTransform](swiftui/projectiontransform.md)
