Swift dynamic table cell height

80,254

Solution 1

You should use UITableViewAutomaticDimension provides a solution for displaying dynamic content.

Use below code in viewDidLoad:

tableView.estimatedRowHeight = YourTableViewCellHeight
tableView.rowHeight = UITableView.automaticDimension

Read more from here

Hope it helps. :)

Solution 2

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
}
Share:
80,254
SpyZip
Author by

SpyZip

Android Developer

Updated on July 09, 2022

Comments