UITableView - change section header color

前端 未结 30 2902
不思量自难忘°
不思量自难忘° 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条回答
  •  旧时难觅i
    2020-11-27 09:32

    If anyone needs swift, keeps title:

    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView(frame: CGRect(x: 0,y: 0,width: self.tableView.frame.width, height: 30))
        view.backgroundColor = UIColor.redColor()
        let label = UILabel(frame: CGRect(x: 15,y: 5,width: 200,height: 25))
        label.text = self.tableView(tableView, titleForHeaderInSection: section)
        view.addSubview(label)
        return view
    }
    

提交回复
热议问题