UITableView - change section header color

前端 未结 30 2894
不思量自难忘°
不思量自难忘° 2020-11-27 08:50

How can I change color of a section header in UITableView?

EDIT: The answer provided by DJ-S should be considered for iOS 6 and above. The accepted

30条回答
  •  时光说笑
    2020-11-27 09:32

    Swift 4

    To change the background color, text label color and font for the Header View of a UITableView Section, simply override willDisplayHeaderView for your table view like so:

    override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
            let header = view as! UITableViewHeaderFooterView
            header.backgroundView?.backgroundColor = .white
            header.textLabel?.textColor = .black
            header.textLabel?.font = UIFont(name: "Helvetica-Bold", size: 14)
    } 
    

    This worked perfectly for me; hope it does help you too!

提交回复
热议问题