Skip to content
Khoa Pham@onmyway133

How to scale image fill without affect layout in SwiftUI

1 min read

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

Keep reading

Type to search titles and full text.

↑ ↓ move↵ openPagefind