动态 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?
推荐答案
设置动态单元格高度过程
- 从顶部和底部固定标签.请参考以下屏幕截图
- 将标签的行数设为 0 与 xcode 的属性检查器相同,也可以通过代码完成,请参阅以下屏幕截图
- 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屋!
查看全文