简体   繁体   中英

Adjust UIImage with Aspect Ratio using Autolayout

Is it possible to automatically resize uiimage based on autolayout with aspect ratio (1:1)?

Btw I'm using collectionview as my view.

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.

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() . Here you can inspect the size of the UIImageView

.

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