Iâ€™m going to demonstrate on how I achieved the dynamic height for my
UITableViewCell. Below is what it looks like.
This is a
UITableViewCell for comments. ImageView on the left side is for the userâ€™s avatar, the top most
UILabel is for the username and lastly at the bottom is the
UILabel for comment.
Yes donâ€™t mind the red warnings, that is by design. The important here is for the
UITableViewCell height to expand with AutoLayout.
First take note of the UIImageViewâ€™s constraints.
Next, the constraints for the username UILabel. As you may notice I did not specified a Height constraint, thus the red error for both UILabels.
And lastly the constraints for our comment UILabel.
Now in your code make sure you set the
commentsTableView.rowHeight = UITableView.automaticDimension
commentsTableView.estimatedRowHeight = UITableView.automaticDimension