简体   繁体   English

使用自动布局以长宽比调整UIImage

[英]Adjust UIImage with Aspect Ratio using Autolayout

Is it possible to automatically resize uiimage based on autolayout with aspect ratio (1:1)? 是否可以根据具有宽高比(1:1)的自动布局来自动调整uiimage的大小?

Btw I'm using collectionview as my view. 顺便说一句,我正在使用collectionview作为我的视图。

Here's my layout in storyboard 这是我在情节提要中的布局

故事板

and here's the result when running the app 这是运行应用程序时的结果

集合视图

You have to add as in picture to make image sacrifice width to fit to aspect ratio constraint 您必须在图片中添加,以使图像牺牲宽度适合宽高比限制

在此处输入图片说明

If you want to have the UIImageView to always be a square and set the an aspect ratio on the width and height. 如果要使UIImageView始终为正方形,并在宽度和高度上设置纵横比。

However if you want to resize the UIImage depending on the size of the imageView then in your custom UICollectionViewCell make the necessary adjustments in the layoutSubviews() . 但是,如果要根据UICollectionViewCell的大小调整UIImage的大小,则在自定义UICollectionViewCell中对layoutSubviews()进行必要的调整。 Here you can inspect the size of the UIImageView 在这里您可以检查UIImageView的大小

.

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

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