简体   繁体   English

如何调整uiimageview的大小以仅适合Aspectfill中的图像?

[英]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. 我为此imageView使用了自动布局,并且在约束中没有设置高度,以为它会调整为图像高度,但似乎无法正常工作。 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. 它在UITableViewCell中,我想根据图像大小进行大小调整。

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. 您必须根据图像尺寸计算UIImageView的高度,然后在代码中设置UIImageView的高度,方法是按照此处所述设置框架高度,或者添加高度约束并将其常数设置为您想要的高度。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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