user1726616 user1726616 - 7 months ago 53
Swift Question

How to change separator line color for single table section?

How to change the separator line color for single table section? I have several sections, but I want to change it only for one of them. In interface builder I can change the color only for all table section separator lines.

switch(indexPath.section){
case 0:
tableView.separatorColor = UIColor.redColor()
break
case 1:
and so on...
}


This one doesn't work for me.

Answer

separatorColor is a property of a UITableView. You can't specify a section and you're therefore not specifying a section. So of course the property applies to the whole table view.

The built-in view can't automatically vary colours by section. You'll have to incorporate the separator into your table view cells, or insert separator cells between your existing cells. It's a pain but your options are limited.