UITableViewController 的基本(静态)单元格标签内的动态类型 - 可能吗? [英] Dynamic Type within Labels of Basic (Static) Cells of UITableViewController - is it possible?

查看:24
本文介绍了UITableViewController 的基本(静态)单元格标签内的动态类型 - 可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是不言自明的,我可能遗漏了一些简单的内容.以下是在 Interface Builder 中完成的.

我创建了一个 UITableViewController,我将内容设置为 Static Cells,将样式设置为 Grouped.

我已经定义了部分的数量以及每个部分的行数.我已将每个单元格的样式设置为 Basic.

现在,在每个单元格中,我都有默认的内容视图和标签.对于标签,我将 Text 设置为 Plain,将 Font 设置为 Body,将 Lines 设置为 0.通常这允许我使用 UILabels 实现动态类型.

我将单元格连接为 IBOutlets 并以编程方式设置它们的文本(仅).

当我运行应用程序时,一切都在那里,除了标签的字体(以及每个单元格的高度)没有改变(不是动态类型).

因此,我的问题是,对于 Basic(非 Custom)静态单元格中的标签是否可以实现动态类型,或者这些单元格是否意味着因为它们是"?

<小时>

我在 SO 上看到的最接近的问题是

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.

解决方案

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
}

这篇关于UITableViewController 的基本(静态)单元格标签内的动态类型 - 可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆