动态更改tableView单元格高度
答
在这里,您可以根据您的文本的长度获取标签(动态)的高度:
// Set space for content height
let frameForPostContentLabel = NSString(string: content).boundingRect(with: CGSize(width: view.frame.width - 32, height: 120), options: NSStringDrawingOptions.usesFontLeading.union(NSStringDrawingOptions.usesLineFragmentOrigin), attributes: [NSFontAttributeName: UIFont.systemFont(ofSize: 15)], context: nil)
,然后你可以设置的tableview的高度:
cell.postContentLabelHeight.constant = frameForPostContentLabel.height
是有是... –
[在UITableView中使用动态单元格布局和可变行高度中的自动布局](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-小区布局-可变行高度) – mgyky