xcode 自动布局:需要 y 位置或高度的约束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47634284/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Autolayout : Need constraints for y position or height
提问by Gaurav Pandey
I am trying to satisfying the constraint form a long time but getting above error i.e. is "Need constraints for y position or height" for Yellow View and Green View. Basically I have 2 UILabel (dynamic height) within UIView and UIImageView of 4:3 ratio within a Cell.
我试图长时间满足约束形式,但遇到错误,即黄色视图和绿色视图的“ y 位置或高度需要约束”。基本上我在一个单元格内的 UIView 和 UIImageView 中有 2 个 UILabel(动态高度),比例为 4:3。
And my applied constraint is
我应用的约束是
I am also including sample project herewith above issue.
我还在此处包含了具有上述问题的示例项目。
回答by Prashant Tukadiya
Just one Constraints required
只需要一个约束
Provide SubHeading label height
>= (Greater than equal to
) Constraints
提供副标题标签height
>= ( Greater than equal to
) 约束
Because of you have applied aspect ratio of UIImageView
of 4:3
so it required to fixed other items height and Y position before it apply a ratio to it.
By giving height to subheading Autolayout is able to calculate approx value min required in image ratio
由于您应用UIImageView
了 4:3 的纵横比,因此在对其应用比例之前需要固定其他项目的高度和 Y 位置。通过为副标题提供高度,Autolayout 能够计算出图像比例所需的近似值 min
Hope it is helpful to you
希望对你有帮助
回答by sRoy
I am attaching two images, one is output and another one is the constraints of views (UILabel, UIImageView). For testing purpose, I put long texts in UILabel, after testing I reduced the text to 'Heading it is' and 'Sub heading it is'. Let me know, if its working of not.enter image description here
我附上两张图片,一张是输出,另一张是视图的约束(UILabel、UIImageView)。出于测试目的,我将长文本放在 UILabel 中,测试后我将文本缩减为“标题是”和“子标题是”。让我知道,如果它不起作用。请在此处输入图像描述