Swift dynamic table cell height [duplicate]
You should use UITableViewAutomaticDimension
provides a solution for displaying dynamic content.
Use below code in viewDidLoad
:
tableView.estimatedRowHeight = YourTableViewCellHeighttableView.rowHeight = UITableView.automaticDimension
Hope it helps. :)
make sure UILabel height constraint not to be constant, if constant it have to set Relation greater than or equal to from attribute inspector
make sure UITableViewestimate row height set as per your.
tableView.estimatedRowHeight = 85
and write in UITableViewCell
class
cell.lbl_name.sizeToFit() cell.lbl_name.numberOfLines = 0
Make sure your UITableViewDelegate
method
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat { return UITableView.automaticDimension}