简体   繁体   English

iOS:使用固定的长宽比将视图约束到后缘或下边缘

[英]iOS: Constraining View with fixed aspect ratio to trailing edge OR bottom edge

I have an ImageView that is constraint to be a square and on its top edge: 我有一个ImageView,它被约束为正方形并在其顶部边缘:

http://i.imgur.com/dACmwPN.png http://i.imgur.com/dACmwPN.png

The problem is that I want the view to fill the entire bottom space without exceeding the superview. 问题是我希望视图填充整个底部空间而又不超过父视图。 In other words it should conform to either the width or the remaining height depending on which one is smaller. 换句话说,它应该符合宽度或剩余高度,取决于哪一个较小。

The guide I am following suggests to add all of these to a stack view, but that is an iOS 9 feature and I want to develop for iOS8. 我遵循的指南建议将所有这些都添加到堆栈视图中,但这是iOS 9的功能,我想针对iOS8开发。 What would be a good solution for that SDK? 该SDK有什么好的解决方案?

I would add width = height constraint to keep the aspect ratio, then bottom and trailing constraints with lower priority (900) and >= margin value (ex 8) . 我将添加width = height约束以保持宽高比,然后添加具有较低优先级(900)和> = margin值(ex 8)的底部约束和尾随约束。 This way image will be a square and it will not go over bottom or right. 这样,图像将是正方形,并且不会超出底部或右侧。 Also aspect fit should be set. 还应设置外观适合度。

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

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