Closed guidev closed 1 year ago
If you need the information of downloaded image, use onSuccess
to get the image, and then refresh the state to update the view's frame modifier
Awesome, thank you.
This did the trick:
var image: URL?
@State var imageSize: CGSize = .zero
var body: some View {
WebImage(url: image)
.onSuccess { image, _, _ in
imageSize = image.size
}
.resizable()
.scaledToFit()
.frame(maxWidth: imageSize.width/UIScreen.main.scale, maxHeight: imageSize.height/UIScreen.main.scale)
}
Hi,
I'm trying to scale in image to fix the content but without exceeding the original size of the image (to not loose quality).
This works as expected:
I'm having trouble replicating the same behaviour with
WebImage
Am I missing something? Is there a way to get the size of the downloaded image?