如何在 UITableView 的页脚标题中使用换行符?
How do I use a line break in the footer title of a UITableView?
我为 table 视图提供了一个页脚标题,如下所示:
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "DEVELOPED BY COMPANY NAME\nIN COMPANY LOCATION"
}
当我 运行 我的代码时,只有 "DEVELOPED BY COMPANY NAME" 出现在页脚中,换行符之外的文本无处可见。我将如何确保看到所有文本?
默认页脚视图是带有 1 行文本的标签。
如果您想要一个包含多行的标签,您必须创建一个视图,然后 return 在函数 viewForFooterInSection
中创建它。
您还需要实现函数 heightForFooterInSection
来为标签提供正确的高度。 (感谢 rmaddy)
如果符合您的设计,您可以在 Interface Builder 中更改为分组 table 样式。
- 在故事板中 - select 你的 viewController - Select table
- Select "Style" 属性 interface-builder
- Select "Grouped"
分组样式默认提供多行页脚。只需覆盖 func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
就是这样。无需额外视图或提供高度。
我为 table 视图提供了一个页脚标题,如下所示:
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
return "DEVELOPED BY COMPANY NAME\nIN COMPANY LOCATION"
}
当我 运行 我的代码时,只有 "DEVELOPED BY COMPANY NAME" 出现在页脚中,换行符之外的文本无处可见。我将如何确保看到所有文本?
默认页脚视图是带有 1 行文本的标签。
如果您想要一个包含多行的标签,您必须创建一个视图,然后 return 在函数 viewForFooterInSection
中创建它。
您还需要实现函数 heightForFooterInSection
来为标签提供正确的高度。 (感谢 rmaddy)
如果符合您的设计,您可以在 Interface Builder 中更改为分组 table 样式。
- 在故事板中 - select 你的 viewController - Select table
- Select "Style" 属性 interface-builder
- Select "Grouped"
分组样式默认提供多行页脚。只需覆盖 func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?
就是这样。无需额外视图或提供高度。