简体   繁体   English

如何调整图像视图的大小以适合图像并适当缩放以适应iPhone Swift

[英]How to resize an image view to fit the image and scale appropriately for an iPhone swift

在此处输入图片说明

I have a UIImageView and a UILabel. 我有一个UIImageView和一个UILabel。

I have added leading and trailing constraints to the margin in the storyboard. 我在情节提要中为边界添加了前导和尾随约束。

I am setting the image in the image view from an array of images each of which is of different size. 我正在从图像数组中设置图像,每个图像的大小各不相同。

The images are aspect fit to the image view , so there is space on right and left of the image view if the image is smaller than the imageview. 图像在纵横比上适合于图像视图,因此,如果图像小于imageview,则图像视图的左右两侧会有空间。

How can I scale an image such that the image view resizes itself based on the size of the image and there is no empty space in the background? 如何缩放图像,以使图像视图根据图像的大小调整自身大小,并且背景中没有空白空间?

I tried adding a height constraint and changing the constant value in the code . 我尝试添加高度限制并更改代码中的常量值。 I have tried most of the solutions online , but hasn't worked. 我已经在线尝试了大多数解决方案,但是没有用。

Any help will be appreciated thank you. 任何帮助将不胜感激,谢谢。

将imageview内容模式设置为居中并删除前导和尾随布局,而可以使用水平和垂直居中布局。

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

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