I have an image of size 320X460 and I want to create an UIImageView
which height should be 450 . To maintain aspect ratio I calculated the width of UIImageView = (320/460)*450 = 313.043 dynamically. And set the contentMode For UIImageView is UIViewContentModeScaleAspectFit . And set the image(320x460) to image view but it is some what blur.
Note: If I don't resize the UIImageView
to 313.043X450 the image is very clear as it is. So what is the mistake I have done?
If I understand the question, this should answer it.
First to set the aspect ratio for the image in your image view.
myView.contentMode = .scaleAspectFit
Next, your image may blur because it is a .png
or another rasterized format. You need to use .pdf
as recommended by Apple or at very least another vectorized format. Rasterized images have values for all pixels in the image, so when the image is stretched too far it just duplicates and blurs pixels. Vectorized images do not blur because they are really just a series of instructions on how to draw/render the corresponding image.
If you are resizing UIImageView
manually, set the content mode to UIViewContentModeScaleAspectFill
.
If you want to keep content mode UIViewContentModeScaleAspectFit
do not resize imageview to 313. Image will adjust maximum possible width and height , keeping it's aspect ratio.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.