Skip to main content

Aspect Ratio

extension Element {
func aspectRatio(_ ratio: CGSize, contentMode: ContentMode = .fit) -> Element
}

Constrains the view’s dimensions to an aspect ratio specified by a CGSize. If this view is resizable, it uses aspectRatio as its own aspect ratio.

Examples

var body: Layout {
VStack {
imageView
.resizable()
.aspectRatio(CGSize(width: 3, height: 2))
Spacer(8)
label
}
}