tableview 单元格中的自增长标签 [英] Self growing label in tableview cell
问题描述
我正在Objective C
中使用Tableview
.
我在一个 TableView 单元格中有 4 个标签.我想根据内容大小展开 Comment Body 标签和 Answer Body 标签.如何使用 AutoLayout.请帮帮我
I have 4 labels in a TableView cell. I want to expand the Comment Body label and Answer Body label according to the content size. How it is possible using AutoLayout. Please help me
如何根据内容设置标签的动态高度?
How to set dynamic height of label as per content?
tableview
的截图如下.
推荐答案
约束
评论正文:- 顶部、尾部、底部
Comment Body :- Top, Trailing, Bottom
答案正文:- 顶部、尾部、底部
Answer Body :- Top, Trailing, Bottom
comment :- 居中 y 到评论正文,领先,水平到评论正文,固定宽度
comment :- Center y to Comment Body, leading, Horizontal to Comment Body , Fix width
答案:- 中心 y 到答案正文,领先,水平到答案正文,固定宽度
Answer :- Center y to Answer Body, leading, Horizontal to Answer Body, Fix width
numberOfLine
0 两个动态标签
代码
将以下代码添加到 ViewDidLoad
或 ViewWillAppear
Add Following code to ViewDidLoad
or ViewWillAppear
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 80;
注意:删除heightForRow
这篇关于tableview 单元格中的自增长标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!