In iOS 8, creating auto resizing
UITableViewCells is really easy.
For this article, I'll take an example where you have a custom cell with just one
- Add constraints to the label. Make sure there are no auto layout errors or warnings. Remember not to add a height constraint because obviously if you fix the height of the label, it can't resize itself.
Another important thing to remember is to set the
Linesproperty of the label to 0. You can do this from the IB itself.
Next add the following two lines of code to the
UITableViewController. 44 is the default height of a cell. You can adjust it all you want.
tableView.estimatedRowHeight = 44 tableView.rowHeight = UITableViewAutomaticDimension
And that's it! Here's the result.