简体   繁体   中英

UIImageView won't resize properly

I have an image which I want to scale accordingly to a certain percentage which I have done this way:

CGRect frame = _image.frame;
frame.size.height = frame.size.height * 0.4 //0.4 is actually a float
_image.frame = frame;

This scales the image properly, although the origin is the center, so the image shrinks in to the middle. When I do the same thing in Interface Builder, I can set the origin to down in the middle and when I change the size of the height it shrinks perfectly only in length. How can I do that programmatically. I tried anchorPoint but that screws everything up, I don't know why.

通过Interface Builder或程序,使用UIViewContentModeScaleAspectFit或其他一些值来设置UIImageView contentMode属性,以满足您的缩放样式。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM