如何在 UITableView 的页脚标题中使用换行符?

Jam*_*mes 2 cocoa-touch uitableview ios

我为表视图提供页脚标题,如下所示:

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
    return "DEVELOPED BY COMPANY NAME\nIN COMPANY LOCATION"
}
Run Code Online (Sandbox Code Playgroud)

当我运行代码时,页脚中仅显示“DEVELOPED BY COMPANY NAME”,并且换行符之外的文本无处可见。我该如何确保所有文字都能被看到?

小智 5

如果它符合您的设计,您可以在 Interface Builder 中更改为分组表格样式。

  1. 在故事板中 - 选择你的 viewController - 选择表格
  2. 在界面生成器中选择“样式”属性
  3. 选择“分组”

分组样式默认提供多行页脚。只需覆盖func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String?

就是这样。无需额外的视图或提供高度。