简体   繁体   English

如何让我的图像完全适合UIView

[英]How can I make my image fit in completely in a UIView

The image I am applying looks fine in IPhone7 plus simulator and in IPhone 5 simulator it is not like what I want. 我正在应用的图像在IPhone7加模拟器和IPhone 5模拟器中看起来很好,它不像我想要的。 I am attaching both the images. 我附上了两张图片。 Please help me. 请帮我。

在此输入图像描述

Second image: 第二张图片:

在此输入图像描述

Constraints: 约束:

在此输入图像描述

像这样我想要两个图像一个在另一个上面

Follow these steps: 跟着这些步骤:

  1. In your storyboard, use Auto Layouts for UIview like this: Add Constraints from left, top, height, width 在故事板中,使用UIview的自动布局,如下所示:从左侧,顶部,高度,宽度添加约束
  2. It will work fine for all Screen 它适用于所有屏幕

Use Propotional Constraints instead of giving fix widh , heigth Constraints . 使用Propotional Constraints而不是给出修复widh,heigth Constraints。

lets say your View has 250 width & 100 height and you are designing cell in 375 width xib. 假设您的View有250宽度和100高度,您正在设计375宽xib的单元格。

Steps of giving Constraints 给予约束的步骤

1 :- Leading Constraints  same as you described in your image.
2 :- Center Vertical Constraints same as you described in your image.
3 :- Give aspect Ratio to your View.
4 :- Give equal width Constarint of Your View with Super View.

multiplier Calculation :-> 250/375 = 0.6666666667 乘数计算: - > 250/375 = 0.6666666667

Edit the last Constarint which name should like this : Propotional Width , edit that Constarint and give multipier as 0.6666666667 编辑最后一个Constarint,其名称应如下所示: Propotional Width ,编辑该Constarint并将multipier设为0.6666666667

runt the application , if you set proper height of cell with delegate method , it should almost work. 如果你用委托方法设置了适当的单元格高度,它应该几乎可以工作。

I think you are using 7 plus screen resolution in storyboard while designing. 我认为你在设计时在故事板中使用7加屏幕分辨率。 Corner radius applies before your constraints load. 在约束加载之前应用拐角半径。

Apply your corner radius in layoutSubviews method after super called. 超级调用后,在layoutSubviews方法中应用您的角半径。

Add the following constraints for that UIView. 为该UIView添加以下约束。

1. Leading space to its superview 2. Trailing space to nearest label 3. Add the constraint Vertically in container 4. Set Width constraint 5. Set height constraint.

Will works perfectly . 会很完美。

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

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