我试图创造一个充满活力的的消息的电池使用自动布局。
I'm trying to create a dynamic message cell using auto-layout.
细胞给出以下约束正确定位,在大多数情况下,用自动布局:
The cell is positioning correctly, for the most part, with auto-layout given the following constraints:
我的第一个问题是消息标签(可复制标签)宽度的限制。这似乎用集preferredMaxLayoutWidth来解决:中的这个问题。
My first problem was the message label (Copyable Label) width was constrained. That seems to be resolved by using setPreferredMaxLayoutWidth: as described in this question.
身高仍然是一个问题。正如你所看到的,消息的泡沫仍然切断。另外,我不知道如何确定表视图的信息单元的高度。
Height is still a problem. As you can see, the message bubble is still cutting off. In addition, I'm not sure how to determine the message cell height for the table view.
我的预期自动布局以某种方式只是工作。我读过这里回答,但似乎很多的步骤。
I expected auto-layout to somehow just work. I've read the answer here, but it seems like a lot to of steps.
首先,就是自动布局比传统的框架算术更复杂的情况下?
First, is a case where auto-layout is more complex than traditional frame arithmetic?
二,使用自动布局,我怎么能确定最终的单元格的高度?
Second, using auto-layout, how can I determine the height of the resulting cell?
推荐答案我充分利用自动布局和你说什么是有点儿问题。我不想修改固有大小为UITable的性能用途计算方法。
I fully use Auto Layout and what you speak about is kinda a problem. I didn't want to modify the way intrinsic size is calculated for performance purpose of UITable.
所以我用一个很简单的方法就是在最后正确的。这是确定,如果你的电池很简单,如果你的单元格中包含多个变量的文本可以成为这样辛苦。
So I used a very simple way that is correct in the end. It's ok if your cell is simple, can become such hard if your cell contains more than one variable text.
我定义我的正常细胞,在那里你可以把适合的插图(没有关于它的问题)一个UILabel。然后,在你的表的数据源,可以直接定义单元格的高度:
I defined my cells normally, where you can put a UILabel that fits the insets (no problem about it). Then, in your table datasource, you define directly the height of the cell:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { return [TEXTOFYOURCELL sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(300, 1000)].height + 31; // Here it's defined for 15 of top and bottom insets, define +1 than the size of the cell is important. }编辑:这里是一些code有关的UILabel在细胞(在init方法)。
EDIT : Here some code about the UILabel in the cell (in init method).
__titleLabel = [UILabel new]; __titleLabel.numberOfLines = 0; [self.contentView addSubview:__titleLabel]; // adding to contentView rather than self is very important ! [__titleLabel keepInsets:UIEdgeInsetsMake(0, 15, 0, 15)];我使用这个API: github/iMartinKiss/KeepLayout 来管理自动布局简单。
更多推荐
使用自动布局iOS的消息单元格的宽度/高度
发布评论