在UITableViewCell中自动增加/减少UILabelView高度? [英] Automatically increase/decrease UILabelView Height in UITableViewCell?
问题描述
你好,我有一个带x#单元格的UITableView。最后一个单元格我有两个UILabel。设置第二个UILabel文本时,我试图让单元格和UILabel调整大小以显示文本。
Hello I have a UITableView with x# of cells. the last cell I have two UILabels. When the second UILabel text is set I am trying to get the cell and the UILabel to resize to show the text.
这是我的内容:
UILabel - LabelBio(橙色)有:
The UILabel - LabelBio (orange) has:
行数:0
基线:对齐基线
线休息:自动换行
自动收缩:固定字体大小
Lines: 0 Baseline: Align Baselines Line Break: Word Wrap Autoshrink: Fixed Font Size
ContentView,LabelSellerInfo和LabelBio的约束设置如下:
The constraints for ContentView, LabelSellerInfo and LabelBio are set as follows:
LabelSellerInfo
LabelSellerInfo
LabelBio
LabelBio
ContentView
ContentView
这些设置在这里是get:
With those settings here is what a get:
我尝试了很多变化,但似乎无法使Bio标签增长和缩小,有时如果我得到标签细胞生长仍然太小。
I have tried many variations but cannot seem to get the Bio label to grow and shrink, sometimes if I get the label to grow the cell is still too small.
任何人都可以帮助我理解我做错了什么,并告诉我如何使约束正确以使其发挥作用?
Can anyone help me to understand what I am doing wrong and show me how to get the constraints correct to get this to work?
谢谢
推荐答案
以下是步骤...
-
希望您了解
autylayout
。使用约束(左侧内容视图
,内容视图右侧
,底部内容视图
和Verticle到你的第一个标签
)
hope you know about
autylayout
. use constraints (left to content view
,right to content view
,bottom to content view
andverticle to your first label
)
然后在你的 viewdidLoad
方法添加 YourTableView.estimatedRowHeight = 200
- >给出你想要的任何高度。
then in your viewdidLoad
method add YourTableView.estimatedRowHeight = 200
-> give any height you want.
最后定义以下方法:
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
你很高兴。
这篇关于在UITableViewCell中自动增加/减少UILabelView高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!