Author Topic: How to change the color of a table view's section header label  (Read 4890 times)

kjmcneish

  • Administrator
  • *****
  • Posts: 719
    • View Profile
How to change the color of a table view's section header label
« on: November 26, 2014, 09:52:54 AM »
To change the color of a table view's section header label, override the tableView:willDisplayHeaderView: method in the view controller. For example, the following code changes the text color of the label to white:

Code: [Select]
override func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
        // If different colors for different sections, check the section number first
        var header = view as! UITableViewHeaderFooterView
        header.textLabel.textColor = UIColor.whiteColor()
}

All the best!
Kevin McNeish
Author of "Learn to Code in Swift": https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
« Last Edit: August 20, 2015, 02:45:53 AM by kjmcneish »