AMAN77 AMAN77 - 2 months ago 8
iOS Question

How do you change the colour of a section title in a tableview?

Here is what I have at the moment.

enter image description here

How do I refer to this so that I can change the text colour to match my index list? The sectionForSectionIndexTitle worked well for adding in the correct section title but how exactly does one access the title element?

Or is it impossible and I need to redraw the view and add it with viewForHeaderInSection?

Answer

you can use the one of UITableViewDelegate's method

func tableView(tableView: UITableView, willDisplayHeaderView view:UIView, forSection: Int) {
    if let headerTitle = view as? UITableViewHeaderFooterView {
       headerTitle.textLabel?.textColor = UIColor.redColor() 
    }
}

for Reference I taken the model answer from here