简体   繁体   English

使用Swift(AutoLayout)固定UIImage的宽度和高度

[英]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 . equal widthequal widthequal heightequal width And I believe going to the top right is because there's no valid horizontal alignment. 我认为转到右上角是因为没有有效的水平对齐方式。

You can add following constraints to uiimageview : 您可以向uiimageview添加以下约束:

(I have give fixed height and width of 300, you can have your own variants) (我给定了300的高度和宽度,您可以有自己的变体)

在此处输入图片说明

And the output will be... 输出将是...

在此处输入图片说明

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

相关问题 使用Autolayout根据宽度的比例设置UIImage高度 - Set UIImage height based on a ratio of the width using Autolayout 在自动布局中重置固定的宽度和高度 - Resetting a fixed width and height in AutoLayout 如何使用自动布局动态调整具有固定宽度的collectionview单元格高度的大小? - How to dynamically size collectionview cell height with fixed width using autolayout? 如何使用自动版式配置视图宽度固定宽度和可变高度 - How to configure view width fixed width and variable height with AutoLayout Swift 3-如何比较UIImage的宽度和高度? - Swift 3 - How to compare UIImage width and height? UICollectionView单元格固定宽度和动态高度使用swift中的约束 - UICollectionView cell fixed width and dynamic height using constraints in swift 在iPhone中从固定宽度查找UIImage的比例高度 - find proportional height of UIImage from fixed width in iphone 使用自动布局确定UIView的宽度-SWIFT - Determining width of a UIView using autolayout - SWIFT 为Swift中的“CropRect”设置固定的宽度和高度 - Set a fixed width and height for the “CropRect” in Swift 在uiimage中以正确的方式快速显示较小或较大的高度,宽度图像 - show small or bigger height, width image in proper way in uiimage in swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM