Beginning iOS 10 Programming with Swift

Chapter 15
Self Sizing Cells and Dynamic Type

Fun is one of the most important and underrated ingredients in any successful venture. If you're not having fun, then it's probably time to call it quits and try something else.

- Richard Branson

In iOS 8, Apple introduces a new feature for UITableView known as Self Sizing Cells. This is seriously one of the most useful features of the SDK. Prior to iOS 8, if you want to display dynamic content in a table view with multiple rows, you have to calculate the row height of a cell manually. Now iOS is capable to determine the row height for you. All you need to do is write a couple lines of code and make sure you define all the layout constraints for the prototype cell (that we have already done).

Self sizing cells are particularly useful to support Dynamic Type. By using Dynamic Type, your app can respond to the text change and allow users to customise the text size to fit their own needs. Dynamic Type is another topic which will be covered in this chapter.

Let's start with self sizing cells. In summary, here are the procedures to implement self sizing cells:

  • Add auto layout constraints in your prototype cell
  • Specify the estimatedRowHeight property of your table view
  • Set the rowHeight property of your table view to UITableViewAutomaticDimension

Want to learn more about Swift 3 and build a real world app? Get a full copy of the book here.