blog icon indicating copy to clipboard operation
blog copied to clipboard

How to scale image fill without affect layout in SwiftUI

Open onmyway133 opened this issue 1 year ago • 0 comments

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())

onmyway133 avatar Jul 30 '23 20:07 onmyway133