OGeek|极客世界-中国程序员成长平台

标题: ios - UITables 部分标题中的多行文本 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 14:32
标题: ios - UITables 部分标题中的多行文本

我一直在搜索并试图让我的 UITableView 部分标题允许多行文本,但我无法让它工作。这是它显示的内容:

enter image description here

但文字是:埃弗顿足球俱乐部的主场 Jersey 是什么颜色的?

我目前正在尝试的是:

func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

        let label = UILabel()
        label.lineBreakMode = .byWordWrapping
        label.numberOfLines = 0
        label.text = question?.question
        return label
}

并将以下内容放在 viewDidLoad 事件中

tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension

但这并没有什么不同。谁能帮帮我?



Best Answer-推荐答案


而不是

tableView.estimatedRowHeight = 44.0
tableView.rowHeight = UITableViewAutomaticDimension

在下面使用

tableView.sectionHeaderHeight = UITableViewAutomaticDimension
tableView.estimatedSectionHeaderHeight = 44

欲了解更多信息,请阅读以下答案 https://stackoverflow.com/a/29763200/1320352

关于ios - UITables 部分标题中的多行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48892111/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4