1
votes

Question is fairly self explanatory and I may be missing something simple. The following is done in Interface Builder.

I have created a UITableViewController, I've set the Content to Static Cells and Style to Grouped.

I've defined the number of Sections as well as the number of Rows for each section. I've set the Style of each cell to be Basic.

Now, within each cell, I have the default Content view and Label. For the label I have set the Text to Plain, Font to Body and Lines to 0. Normally this allows me to achieve Dynamic Type with UILabels.

I hook up the cells as IBOutlets and set their text (only) programmatically.

When I run the app, everything is there, except that the Font of the labels (as well as the height of each cell) is unchanged (not Dynamic Type).

Therefore, my question is, can Dynamic Type be achieved for a label within a Basic (non Custom) Static Cell or are these cells meant to be "as they are"?


The closest question I've seen on SO is this, however it refers to Custom Cells.

Also tried implementing

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.rowHeight = UITableViewAutomaticDimension
}

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

but to no avail.

1

1 Answers

0
votes

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 (e.g. "Title 3").

If you want the cell height to adjust accordingly, make sure you have both top and bottom constraints. And as you discovered, you can't just set the row height to UITableViewAutomaticDimension, but rather you have to implement that delegate method, e.g. in Swift 3:

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.estimatedRowHeight = 44
}

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return UITableViewAutomaticDimension
}

sample