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)
You should use .resizable()
before applying any size modifications on an Image
.
Image(room.thumbnailImage).resizable()
.frame(width: 32.0, height: 32.0)
And how do you resize the image keeping the aspect ratio?
@MarkKang I didn't try it, but there is a method named
aspectRatio(_:contentMode:)
That method requires you to specify the aspect ratio. I would like to keep the original aspect ratio of the image but constrain it to best fit by frame height, centering the image content and cropping by the frame.
Image("image01") .resizable() .aspectRatio(UIImage(named: "image01")!.size, contentMode: .fit)
Image("name").resizable().scaledToFit()
isn't bugged, though. So you can wrap your image in a view, adjust the frame of the view to whatever size you need, thenscaledToFit()
will then make the image as big as it can be while keeping aspect ratio.