约束来指定视图大小取决于多个子视图 [英] Constraints to specify when view size is dependent on multiple subviews

查看:143
本文介绍了约束来指定视图大小取决于多个子视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的自定义单元格中的的UITableView 。有在细胞4次。 3 的UILabel 和1 的UIImageView (灰色的),如下图所示。标签的文字是动态的,所以宽度和高度是动态的。

I am using custom cell in UITableView. There are 4 views in cell. 3 UILabels and 1 UIImageView (grey colored one) as shown below. Text of labels are dynamic so width and height is dynamic.

的UIImageView 的下面宽度取决于2标签。所以,问题是指定标签和之间的约束的UIImageView 将决定的UIImageView 的宽度。

Here width of UIImageView depends on 2 labels. So issue is to specify constraints between labels and UIImageView that will decide the width of UIImageView.

请参见下面如果第一个标签的文本很长,会发生什么。

See below what happens if first label's text is long.

如何解决在宽度取决于多个标签宽度指定约束条件?

How to specify constraints when width depends on width of multiple labels?

更新:我试图设置标签的行数为0和内在大小占位符。它不工作了。下面是它的外观。我试着设置内在的宽度和高度没有,但是当我做了两个标签,而不是让错误,如果把它给了错误只有一个标签。

Update : I tried setting number of lines for labels to 0 and intrinsic size to placeholder. It's not working, too. Below is how it looks. I tried setting intrinsic width and height to none, but it gives error when I do that for both label, not giving error if set that for only one label.

更新:我改变性质和下方会显示现在他们是什么以及如何显示单元

Update : I changed properties and below is displayed what are they now and how the cell is displayed.

细胞:

在第一行(粉红色)为约束标签:

在第二行(蓝绿色)标签约束:

推荐答案

我很多东西后,实验解决了这个。我不得不这样做的唯一一件事就是为设置水平和垂直内容融为一体pression性优先要求 .i.e。 1000。
我这样做是为了所有的标签,因为我不希望任何标签的削减他们的内容。

I solved this after experimenting with lot of things. The only thing I had to do is to set horizontal and vertical content compression resistance priority to required.i.e. 1000. I did this for all labels because I don't want any of the labels to trim their content.

还有一个是太重要的事情就是获取右边身高细胞中。如果有,即使为1pt误差在计算自定义单元格的高度预期它将不被显示。

One more thing which is too much important is Getting Right Height Of Cell. If there is even 1pt of error in calculating custom cell's height it will not be displayed as expected.

提示:


  1. 如果任何观点的高度大于预期的可能,然后计算出细胞的高度比实际需要更多的。

  2. 如果任何意见正在缩小垂直或不那么显示全部内容细胞可能计算高度比实际需要较少。

同比可以测试是否高度错了添加/删除常量值,高度(变量),你计算的单元格。

Yoy can test if height is wrong by adding/removing constant value to height (variable) you calculate for cell.

这篇关于约束来指定视图大小取决于多个子视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆