UITableView - change section header color

前端 未结 30 2897
不思量自难忘°
不思量自难忘° 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:34

    The following solution works for Swift 1.2 with iOS 8+

    override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
    
        // This changes the header background
        view.tintColor = UIColor.blueColor()
    
        // Gets the header view as a UITableViewHeaderFooterView and changes the text colour
        var headerView: UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView
        headerView.textLabel.textColor = UIColor.redColor()
    
    }
    

提交回复
热议问题