2015-07-12 218 views
0

是否有任何方法來增加或減少表視圖中單元格的高度取決於其中的標籤文本?動態更改tableView單元格高度

+0

是有是... –

+0

[在UITableView中使用動態單元格佈局和可變行高度中的自動佈局](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-小區佈局-可變行高度) – mgyky

回答

0

在這裏,您可以根據您的文本的長度獲取標籤(動態)的高度:

// 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 
相關問題