0

Is there any method to increase or decrease the cell's height in a table view depending on text of a label in it?

Ozgur Vatansever
  • 49,246
  • 17
  • 84
  • 119
swapna
  • 1
  • 2
  • possible duplicate of [Using Auto Layout in UITableView for dynamic cell layouts & variable row heights](http://stackoverflow.com/questions/18746929/using-auto-layout-in-uitableview-for-dynamic-cell-layouts-variable-row-heights) – MGY Jul 12 '15 at 13:34

1 Answers1

0

Here you can get the height of the label (Dynamically) depending on the length of your text:

// 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)

and then you can set the height of the tableview:

cell.postContentLabelHeight.constant = frameForPostContentLabel.height
Buka Cakrawala
  • 189
  • 1
  • 8