Dynamic type "Body" style doesn't work in a UITableView with static cells

359 Views Asked by At

I'm designing a table view with static cells in Interface Builder, and I want the text size to change to support dynamic type. I've created a cell with "Basic" style, which means it contains one automatic label, and set the size of the label to "Body". But the font is always 17 points regardless of the dynamic type setting. This doesn't happen with labels I manually add to "Custom" style cells.

Screenshot:

The cell at the top is the problematic one. It's 17 points even though I've turned the dynamic type font size all the way down. The second cell was created by manually adding a label to a "Custom" style cell and setting the font size to "Body"; this is what the first cell should look like. The third label is a "Basic" style cell fixed at 17 points, for comparison.

MVCE is available here: https://drive.google.com/file/d/1-3di9-WWVsjcbktD6mxAyU4BrLR_g6nG/view. I unfortunately can't paste the code into the question because there is no code, only a storyboard. Here's how I made it:

  • Create a new single view project
  • Delete the view controller from the storyboard
  • Add a new UITableViewController, set it as the initial view controller
  • Select the table view and change "Content" to "Static Cells"
  • For the first cell: change "Style" to "Basic", then select the label and change Font to Text Styles - Body
  • Second cell: leave Style as Custom, drag in a label, and change Font to Text Styles - Body (same as above)
  • Third cell: change Style to Basic and don't change text size
1

There are 1 best solutions below

0
On

Actually, the only solution I figured out on my side for this problem is to switch the style to Custom ⟹ you can't use the Dynamic Type feature as expected with Basic static cells.

Other use cases have encountered this situation as explained in this stackoverflow answer:

Dynamic type does work with static tables, but in my tests, just not with "Basic" cell type.
Change it to a "Custom" cell type, add your label and the four constraints, and make sure to choose one of the dynamic fonts.

... and this site details every steps to get the result with illustrations if need be:

To overcome this problem we must set the table view cell style to ‘Custom’ and drag a label (or labels) in ourselves.