Skip to content

Instantly share code, notes, and snippets.

@huynguyencong
Created April 16, 2024 04:16
Show Gist options
  • Save huynguyencong/0364839959b9d086558ec80b10d0ac52 to your computer and use it in GitHub Desktop.
Save huynguyencong/0364839959b9d086558ec80b10d0ac52 to your computer and use it in GitHub Desktop.
A way to put an image in a parent view, filled in an area with a specific aspect ratio
VStack {
Color.clear
.aspectRatio(16/9, contentMode: .fit)
.overlay {
Image(systemName: "icon")
.resizable()
.scaledToFill()
}
.clipped()
Text("Title")
Spacer()
}
.frame(width: 200, height: 100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment