Auto Layout Dynamic Height for UITableViewCell with Custom Fonts and Storyboard

Paul Solt · 42K views · 2014 · 1:02:19

Open on YouTube

Software (other)UX & UI designtutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about sizing table view cells dynamically with Auto Layout, since it walks through the setup and its pitfalls step by step.

Recommended by 2 people across 2 different months, 2014 to 2014.

What it is

A one-hour iOS tutorial by Paul Solt on making UITableViewCell heights adapt to their content with Auto Layout, using custom fonts and Storyboards. It covers setting up constraints in cell subclasses, computing height with a cached cell in heightForRowAtIndexPath:, using estimatedHeightForRowAtIndexPath: for faster loading, and recovering from common mistakes.

What people said

Strong rec rfj001 · 2014-10 · Stack Overflow · on “Increase the main tableview row height according to the custom cell”

This video [this video] gives a great tutorial on using autolayout to dynamically size UITableViewCells. When I needed to do this for an application I ended up subclassing UITableViewCell and setting my constraints programmatically, and it worked like a charm.

Recommends Arun Balakrishnan · 2014-11 · Stack Overflow · on “Fit Text in UItableView Cell”

You have to set up Autolayout constraints for the label and create a prototype cell with the content. And then you have to return then you have to get the height of the cell. For reference , you could see the following video [this video]

Cites YShin · 2014-07 · Stack Overflow · on “AutoLayout breaks constraints when layoutIfNeeded() is called”

I'm trying to implement a dynamic height UITaleViewCell in UITableView with XCode6 using Swift. I laid out my cell as following, by setting up the constraints graphically(Screenshot is from XCode5, because of NDA on XCode6). I also set the BodyLabel's Line Break property to 'Word Wrap', and set the Line number to '0' to allow multiple lines. Now if I just set up the cell's contents inside tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) method, then I get the dynamic height behavior correctly. However, since I was following along tutorials available online(specifically this one [this video] ), I added another method to determine the height of the cell with tableVi