Reputation: 8604
I have a tableViewCell with a label inside that could be multiple lines tall. I've set the label's Lines
property to 0. However, when I make the label's text have multiple lines the text gets cut off. Here's how I've set up my storyboard:
Does anybody know how I made the table's cells just tall enough to contain the labels within?
Upvotes: 0
Views: 711
Reputation: 3598
Setting Dynamic Cell height procedure
Implement delegates of table view mentioned below
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableViewAutomaticDimension
}
func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
return 50 // also UITableViewAutomaticDimension can be used
}
Upvotes: 3
Reputation: 2020
You are missing the bottom constraint from the label to the table view cell (as far as I can tell). In order to make autolayout know how large the height of the cell has to be, you need to supply those constraints.
In addition do not forget to provide the estimatedRowHeight
to the table view. If that value is not given, automatic cell sizing will not work.
Upvotes: 0