Ios – How to change font color of the title in grouped type UITableView

fontsiosiphoneuitableview

I have a grouped type table view and it looks pretty cool.

But, if I change the background color of the table to black, the titles becomes unclear.

Is it possible to change the font color and its styles so that I can make it more readable? Should I implement the tableView:viewForHeaderInSection: method?

Best Answer

If you just need to change the color or font on the header, use tableView: willDisplayHeaderView: forSection:. Here is an example in swift:

Swift v5:

override public func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {

    if let view = view as? UITableViewHeaderFooterView {
        view.backgroundView?.backgroundColor = UIColor.blue
        view.textLabel?.backgroundColor = UIColor.clear
        view.textLabel?.textColor = UIColor.white
    }
}

Original:

override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {

    if let view = view as? UITableViewHeaderFooterView {
        view.backgroundView?.backgroundColor = ThemeBlue
        view.textLabel.backgroundColor = UIColor.clearColor()
        view.textLabel.textColor = UIColor.whiteColor()
    }

}