Reputation:
Is there a way to color every other cell one color on a tableView
? I tried looking into the properties for my tableView
but were not able to find anything.
I want it like this:
tableview
cell - white
cell - gray
cell - white
cell - gray
etc...
Upvotes: 1
Views: 877
Reputation: 1789
One line code, if you want
cell.backgroundColor = indexPath.row % 2 == 0 ? .white : .gray
Upvotes: 8
Reputation: 38833
The easiest way will be to do this programmatically in your cellForRowAt
function:
if indexPath.row % 2 == 0 {
cell.backgroundColor = UIColor.white
} else {
cell.backgroundColor = UIColor.gray
}
Upvotes: 2