谁能帮我解决 viewForHeaderInSection
中缺少的代码?
我必须创建一个 UILabel 吗?
究竟应该如何更改表格标题部分的字体?
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat
{
return 55.0;//Choose your custom row height
}
func numberOfSections(in tableView: UITableView) -> Int {
return self.hoursArray.count
}
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView {
//Code missing!
}
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return self.hoursArray[section]
}
最佳答案
删除此功能,它应该可以使用默认标签。
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView {
}
对于自定义 header ,您可以返回任何 View ,这里是 UIlabel 的示例。
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView {
let label = UILabel.init(frame: CGRect.init(x: 0, y: 0, width: tableView.frame.size.width, height: 30))
label.textColor = UIColor.red
label.text = self.hoursArray[section]
return label
}
关于ios - 更改表格标题部分的字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45025181/