iosswiftswiftui

How to resize Image with SwiftUI?


I have a large image in Assets.xcassets. How to resize this image with SwiftUI to make it small?

I tried to set frame but it doesn't work:

Image(room.thumbnailImage)
    .frame(width: 32.0, height: 32.0)

Solution

  • You should use .resizable() before applying any size modifications on an Image.

    Image(room.thumbnailImage)
        .resizable()
        .frame(width: 32.0, height: 32.0)