首页 > 解决方案 > UITableView titleForHeaderInSection 很大,字体不同

问题描述

我试图让它看起来就像设置页面一样。但是,当我向标题添加标题时,字体看起来是:粗体、comic sans 和 18pt。有任何想法吗?

我尝试了下面的故事板和代码:

override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
    return ("hi")
}

在此处输入图像描述

在此处输入图像描述

标签: swiftuitableview

解决方案


您可以实现 UITableView 可选方法 viewForHeaderInSection 并返回具有所需字体和大小的自定义标签

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

如果您需要在 section 中为 Header 指定不同的高度,则还需要实现可选方法 heightForHeaderInSection。

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat

推荐阅读