简体   繁体   English

根据子视图高度约束设置超视图高度约束

[英]set superview height constraint according to subview height constraint

在此输入图像描述

1) View A , view B , View C height & width are equal 1)视图A,视图B,视图C的高度和宽度相等

2) View A height depends on Label1 & Label2 height 2)视图高度取决于Label1和Label2高度

3) View B height depends on Label3 3)视图B高度取决于Label3

4) View c height depends on Label4 4)视图c高度取决于Label4

5) I want to take max height from View A, View B & View C but all are equal 5)我想从视图A,视图B和视图C中获取最大高度,但都是相同的

6) View X heights depend on max of (View A,View B & View C) 6)视图X高度取决于最大值(视图A,视图B和视图C)

How to achieve this through auto-layout? 如何通过自动布局实现这一目标?

Thanks in advance 提前致谢

It can be done easily in the Xib or storyboard. 它可以在Xib或故事板中轻松完成。 Refer to the Screen shot of the constraints created. 请参阅创建的约束的屏幕截图。

有约束的布局

V1 --> First View V1 - >第一视图

V2 --> Second View V2 - >第二视图

V3 --> Third View V3 - >第三视图

V1L1 --> First View's First Label V1L1 - > First View的第一个标签

V1L2 --> First View's Second Label V1L2 - > First View的第二个标签

V2L1 --> Second View's First Label V2L1 - >第二视图的第一个标签

V3L1 --> Third View's First Label V3L1 - >第三视图的第一个标签

The first View is Having the width constraint of 180 and all the views(V1, V2, V3) are having equal width and equal height constraints. 第一个视图的宽度约束为180,所有视图(V1,V2,V3)具有相等的宽度和相等的高度约束。

All the Labels Lines count is set to zero in the attribute inspector, This enables the label height increase as text of the label is more. 在属性检查器中,所有标签行数都设置为零 。这样可以使标签高度增加,因为标签的文本更多。

The height of V1, V2 and V3 is determined by the content of the labels. V1,V2和V3的高度由标签的内容决定。

Views height increases based on the labels content and all the view are given equal heights , Hence the Content view height will be the height of the max(V1.height, V2.height, V3.height) . 视图高度根据标签内容增加,并且所有视图都具有相等的高度,因此内容视图高度将是max(V1.height, V2.height, V3.height)高度max(V1.height, V2.height, V3.height) Also V1.height = V2.height = V3.height = max(V1.height, V2.height, V3.height) 另外V1.height = V2.height = V3.height = max(V1.height, V2.height, V3.height)

Below is at the clear image of constraints. 下面是约束的清晰图像。

约束顶部图像约束底部图像

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

相关问题 如何设置自动布局约束,以使UIImageView的高度等于超级视图的高度? - How to set autolayout constraint so that the height of an UIImageView is equal to the height of the superview? 根据最高的子视图按钮自动调整超视图高度 - Autosizing superview height according to tallest subview button 如何根据动态高度单元格设置UITableView的高度限制? - How to set height constraint of UITableView according to dynamic height cells? 基于子视图约束的超级视图未增加高度 - Superview not increasing in height based on the subviews constraint 设置UITextView的高度约束 - Set height constraint for UITextView 基于屏幕(超级视图)高度的iOS顶部对齐约束 - iOS Top Alignment constraint based on screen (superview) height 添加等于Superview高度倍数的垂直空间约束 - Adding vertical space constraint equal to superview height multiple Swift-根据UITextView布局约束的UITableViewCell高度 - Swift - UITableViewCell height according to UITextView layout constraint 锚点约束缩小超级视图而不是扩大子视图 - Anchor constraint shrinks superview instead of enlarging subview 更改UIView约束高度会带来其子视图的约束警告 - Change UIView constraint height brings its subview's constraints warning
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM