动态tableViewCell高度 [英] Dynamic tableViewCell height
本文介绍了动态tableViewCell高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个tableViewCell,里面的标签可能是多行高.我已将标签的Lines
属性设置为0.但是,当我使标签的文本具有多行时,文本将被截断.这是我设置情节提要的方法:
I have a tableViewCell with a label inside that could be multiple lines tall. I've set the label's Lines
property to 0. However, when I make the label's text have multiple lines the text gets cut off. Here's how I've set up my storyboard:
有人知道我如何使桌子的单元格高到足以容纳其中的标签吗?
Does anybody know how I made the table's cells just tall enough to contain the labels within?
推荐答案
设置动态像元高度程序
- 从顶部和底部固定标签.请参考以下屏幕截图
- 从xcode的属性检查器中将标签的行数设置为0 ,也可以通过代码完成,请参考以下屏幕截图
- Set numbers of line to 0 of the label as from property inspector of xcode, it can be done from code too please refer following screen shot
-
下面提到的表视图的实现委托
Implement delegates of table view mentioned below
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 50 // also UITableViewAutomaticDimension can be used
}
这篇关于动态tableViewCell高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文