简体   繁体   中英

How to resize uiimageview to fit only the image in aspectfill?

Im using auto layout for this imageView and I don't have a height set in the constraints thinking it would resize to the image height but it doesn't seem to work. Here is a pic:

http://imgur.com/JtpTKVx

I want to remove the red space which is the background and just have the image

it is in a UITableViewCell which i want to size according to the image size.

There isn't a way to do this declaratively. You'll have to calculate how high the UIImageView needs to be based on your image dimensions, then set the height of the UIImageView in code, either by setting the frame height as described here , or by adding a height constraint and setting its constant to your desired height.

您将uiview放进去,并将背景色设置为白色,并将框架设置为uitableviewcell,并放入图像UIView中。

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