根据内容/文本自动布局4 UILabels垂直高度

时间:2015-07-25 12:36:17

标签: ios objective-c uitableview autolayout

我有一个UITableViewCell,我正在使用UITableViewAutomaticDimension自动计算行高。

(我正在复制iOS评论的设计)

我需要将所有4个标签的高度调整到其内容的高度。

  

CC =内容压缩CH =内容拥抱[水平/垂直]

     

标签1:CC = 750/750            CH = 249/750

     

标签2:CC = 999/999            CH = 999/999

     

标签3:CC = 750/749            CH = 249/749

     

标签4:CC = 1000/1000            CH = 1000/1000

此处,标签2和标签4是最重要的标签。我不希望它们无论如何缩小。标签1和标签3可以缩小但是达到极限。(让我们说30px)

我的手机如下: enter image description here

我得到了这个结果: enter image description here

如果有人需要更多信息,请告诉我。

2 个答案:

答案 0 :(得分:1)

我试图复制您的表格视图单元格结构,但似乎问题是未设置preferredMaxLayoutWidth个标签。

您可以在Interface Builder中显式设置它,也可以覆盖表格视图单元格的updateViewConstraints方法:

-(void)updateViewConstraints {
    CGFloat gap = 40.0; // sum of leading and trailing space
    [super updateViewConstraints];
    label.preferredMaxLayoutWidth = self.view.bounds.size.width - gap;
}

答案 1 :(得分:0)

您为Label2和&amp ;;设置了布局约束Lines = 0Label1。 Label4。见下图: enter image description here

top constraintsuperview设置为Vertical Spacing,否则将Label3设置为以上标签。以下是eq的大小内容的结果。

enter image description here

enter image description here

编辑:您的自定义单元格如下: enter image description here

您应该根据元素视图容器更新布局。

相关问题