简体   繁体   中英

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

在此处输入图片说明

I have a UIImageView and a 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.

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内容模式设置为居中并删除前导和尾随布局,而可以使用水平和垂直居中布局。

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