我对UILabel在UITableView上有问题。我想带电影的情节在UILabel,但当申请开始,我只有一行非完整的情节,但当我滚动和向上,我得到完整的电影的情节与2-3行。会有什么问题?


在UILabel首选项中,我选择0行(它使标签是多行的)。在ViewController中,在"viewDidLoad“中,我编写了两行代码,以使单元格可调整大小:
self.searchTableView.estimatedRowHeight = 44.0
self.searchTableView.rowHeight = UITableViewAutomaticDimension发布于 2015-08-26 10:08:39
在设置[view layoutIfNeeded]文本后调用UILabel。它将再次布局子视图。
发布于 2015-08-26 10:07:05
使用多行UILabel,您必须帮助它知道什么时候在布局期间包装文本。
要做到这一点,您需要设置preferredMaxLayoutWidth属性。请参阅ref/occ/instp/UILabel/preferredMaxLayoutWidth
因此,在cellForRowAtIndexPath方法中添加如下内容:
cell.yourUILabelIBOutlet.preferredMaxLayoutWidth = tableView.frame.size.width;发布于 2017-12-14 18:36:48
您可以使用UITableViewCell中的autolayout来实现这一点。对我来说很管用。
设置表视图单元格高度
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
tableView.estimatedRowHeight = 150
return UITableViewAutomaticDimension
}https://stackoverflow.com/questions/32223174
复制相似问题