Replies: 2 comments 1 reply
-
Hi, @JetForMe When applying For your purpose, I guess try the |
Beta Was this translation helpful? Give feedback.
-
My view works fine for a regular image. The problem is not |
Beta Was this translation helpful? Give feedback.
-
I’m having an issue where I can't get
KFImage
to set the aspect ratio of the loaded image without blowing up both the placeholder and the loaded image. If I don't specify.aspectRatio
onKFImage
, then everything mostly works: Prior to loading, the placeholder is okay. But after loading, the loaded image is non-uniformly scaled.To clip an image to a particular aspect ratio, and allow the parent to dictate the size, you make an image resizable, aspect fill, and set the layout priority to -1. This works well.
But trying to set the layout priority on
KFImage
seems to have no effect. I think that’s what’s causing my issues.I’d sure appreciate some help. Thanks!
Trying to fix this by adding
.aspectRatio
toKFImage
blows up both images. Here's a copy of my Stack Overflow question, with screenshots and code:I’m having some issues with
KFImage
. It works fine with the placeholder image, until the remote image is loaded. It seems to be some interaction between.aspectRatio()
and.layoutPriority(-1)
.I have a kind of card with an image, and a couple text blocks beneath it. I want the image to be clipped to a view that has a specific aspect ratio, and whose width is dictated by the container (in the real app these live in a grid, and size will vary from device to device. I want the image to grow, rather than the spacing to grow).
Here’s what I get with the placeholder (the bubbles) and the loaded image (the aspect ratio test image). The placeholder image is 654 x 768, and the loaded image is 1080 x 1920. The aspect ratio of the placeholder is properly maintained, and it is clipped to the desired aspect ratio.
But as you can see, the loaded image is scaled non-uniformly to fit in the same aspect-ratio as the placeholder. The normal solution to that is to add
.aspectRatio(.fill)
. But if I do that onKFImage
, it blows up everything:Here’s the code. Note the
.aspectRatio(contentMode: .fill)
onKFImage
is commented out. If you uncomment it, you get the second image above.Beta Was this translation helpful? Give feedback.
All reactions