[英]How can I make my image fit in completely in a UIView
Follow these steps: 跟着这些步骤:
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.