Ios 如何更改分组uitableview的标题字体?
我有一个分组表视图,希望更改节标题的字体样式。我试过:Ios 如何更改分组uitableview的标题字体?,ios,swift,Ios,Swift,我有一个分组表视图,希望更改节标题的字体样式。我试过: func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { let header = view as! UITableViewHeaderFooterView header.textLabel?.font = UIFont(name: "Futura", siz
func tableView(tableView: UITableView, willDisplayHeaderView view: UIView,
forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel?.font = UIFont(name: "Futura", size: 11)
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UITableViewHeaderFooterView.init(frame: CGRect.init(x: 0, y: 0, width: tableView.bounds.width, height: tableView.sectionHeaderHeight))
view.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
view.contentView.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 0)
let label = UILabel.init(frame: CGRect.init(x: 20, y: 0, width: tableView.bounds.width, height: tableView.sectionHeaderHeight))
label.font = UIFont(name: "Futura", size: 11)
label.textColor = UIColor.blue
view.addSubview(label)
return view
}
我一次一个地尝试了上面的代码,但似乎没有任何效果。请帮忙。谢谢 我试着去做。它起作用了
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
header.textLabel?.font = UIFont(name: "Futura", size: 15)
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UITableViewHeaderFooterView.init(frame: CGRect.init(x: 0, y: 0, width: tableView.bounds.width, height: tableView.sectionHeaderHeight))
view.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
view.contentView.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 0)
view.textLabel?.text = "Hello"
return view
}
或
我希望这会对您有用。它会引发异常还是只呈现默认UIFont?Hi@Emptyless,它呈现默认UIFont。太好了,第二个有效!!我感谢你的帮助!:)
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
let header = view as! UITableViewHeaderFooterView
//
let label = header.viewWithTag(1000) as? UILabel
label?.font = UIFont(name: "Futura", size: 15)
}
override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 40
}
override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let view = UITableViewHeaderFooterView.init(frame: CGRect.init(x: 0, y: 0, width: tableView.bounds.width, height: tableView.sectionHeaderHeight))
view.contentView.layoutMargins = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
view.contentView.backgroundColor = UIColor.init(red: 235/255, green: 235/255, blue: 235/255, alpha: 0)
let label = UILabel.init(frame: CGRect.init(x: 20, y: 0, width: tableView.bounds.width, height: tableView.sectionHeaderHeight))
label.font = UIFont(name: "Futura", size: 11)
label.textColor = UIColor.blue
view.addSubview(label)
label.text = "Hello"
label.tag = 1000
return view
}