Skip to content

Instantly share code, notes, and snippets.

@eyeezzi
Last active January 9, 2017 23:29
Show Gist options
  • Save eyeezzi/07770e656cfaa2205898ae589f2d8f23 to your computer and use it in GitHub Desktop.
Save eyeezzi/07770e656cfaa2205898ae589f2d8f23 to your computer and use it in GitHub Desktop.
UITableViewCell with automatic height using autolayout
/*
Ensure the cell has complete constraints from top to bottom, i.e all the subviews of the cell's contentView should have unambigous constraints from top to bottom.
*/
/* For UITableViews with Prototype cells */
// in viewDidLoad
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 150 // an arbitrary number for estimation
/* For UITableViews with Static cells (Those typically created in IB) */
// in viewDidLoad
self.tableView.rowHeight = UITableViewAutomaticDimension
self.tableView.estimatedRowHeight = 150 // an arbitrary number for estimation
// in tableView delegate
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment