简体   繁体   中英

Fixed width and height of the UIImage using Swift (AutoLayout)

I am trying to put my image at the center & want to keep the width & height of the image fixed.

I have tried adding constraints : equal width, equal height and have also added a constraint to keep some padding below the label.

When I run it, the size of the image is scaled up and it goes to the top right.

I have tried a lot of permutations & combinations to get it where it in the middle, not of them as worked so far.

According to your requirement, set the constraints

  • Horizontally in container
  • Vertically in container
  • Width
  • Height

Not equal width , equal height . And I believe going to the top right is because there's no valid horizontal alignment.

You can add following constraints to uiimageview :

(I have give fixed height and width of 300, you can have your own variants)

在此处输入图片说明

And the output will be...

在此处输入图片说明

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