【发布时间】:2017-12-16 14:40:31
【问题描述】:
我有一些问题。我尝试制作自定义表格标题部分。这是我的代码:
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let sectionHeader = UIView(frame: CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 36))
sectionHeader.backgroundColor = #colorLiteral(red: 0.1215686277, green: 0.01176470611, blue: 0.4235294163, alpha: 1)
tableView.backgroundColor = colors.background
let headerName = UILabel(frame: CGRect(x: 15, y: 0, width: tableView.frame.size.width, height: sectionHeader.frame.size.height))
headerName.font = UIFont(name: "Helvetica", size: 12)
headerName.text = sectionHeaders[section]
headerName.backgroundColor = #colorLiteral(red: 0.9529411793, green: 0.6862745285, blue: 0.1333333403, alpha: 1)
headerName.clipsToBounds = true
sectionHeader.addSubview(headerName)
return sectionHeader
}
我用蓝色和黄色标记并注意到,标签高度与 headerview 不同。有人可以帮助我如何管理文本标签高度到标题视图高度,以及如何垂直对齐文本
【问题讨论】:
-
你用过
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int)吗?
标签: ios swift uitableview