blog
blog copied to clipboard
How to scale image fill without affect layout in SwiftUI
Instead of letting the Image decide the size, we can put it as background
or overlay
. I use clipped
and contentShape
to avoid the fill image obscuring touch event
Color.clear
.frame(height: 100)
.overlay {
AsyncImage(url: item.imageUrl) { image in
image
.resizable()
.scaledToFill()
} placeholder: {
ProgressView()
}
}
.clipped()
.contentShape(Rectangle())