1

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.

Community
  • 1
  • 1
Andy
  • 1,307
  • 1
  • 12
  • 17

1 Answers1

0

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

Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • Thanks Rob. I guess that "Custom" Cells it is then. Pity considering the default cells meet the requirements in so many circumstances. How would you go about adding a Detail Label in the Accessory View? Adding another label and making it gray? What about the size ratio though - is it the same font as the main label? – Andy Nov 08 '16 at 00:59
  • I'm not sure what you mean by "detail label in the accessory view" as usually you don't put labels in the accessory. But, you can add whatever labels you want to your custom cell itself, setting the font to be whatever `UIFontTextStyle` that offers the right relative size against whatever `UIFontTextStyle` you used for the other label. – Rob Nov 08 '16 at 20:13
  • I didn't explain myself too well, I was referring to cells with Style as `Right Detail` which appear to hold a (gray) label inside the accessory view or at least overlap its position. Since these cells (just like the `Basic` cells) do not lend themselves to Dynamic Type, I was just wondering what dynamic font should be used for the "detail" label to mimic the original style of a `Right Detail` cell. – Andy Nov 09 '16 at 02:00
  • You might have to share a screen snapshot, because when I use "Right Detail", both the title and the detail are the same font and color. But when I use "Subtitle" cell, on the other hand, the detail is smaller, something close to "Title 3" for title and "Caption 1" for the subtitle (I'm just eyeballing it). But you're changing this in IB, so just try a few of these "text styles" and you'll see precisely what it will look like. No guessing needed. Pick whichever looks best for your app. – Rob Nov 09 '16 at 17:28
  • Indeed, I must have seen the "Right Detail" too many times under a different aspect when in fact the default is not. You're the man, and a legend here. – Andy Nov 10 '16 at 01:53