Last active
January 9, 2017 23:29
-
-
Save eyeezzi/07770e656cfaa2205898ae589f2d8f23 to your computer and use it in GitHub Desktop.
UITableViewCell with automatic height using autolayout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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