how to set different background colors for cells in a UITableView (specifically rainbow color for seven cells)
See Question&Answers more detail:oshow to set different background colors for cells in a UITableView (specifically rainbow color for seven cells)
See Question&Answers more detail:osSet the backgroundColor
property:
cell.backgroundColor = [UIColor redColor];
Note that the backgroundColor must be set in the tableView:willDisplayCell:forRowAtIndexPath:
method (from UITableViewCell reference):
Note: If you want to change the background color of a cell (by setting the background color of a cell via the backgroundColor property declared by UIView) you must do it in the tableView:willDisplayCell:forRowAtIndexPath: method of the delegate and not in tableView:cellForRowAtIndexPath: of the data source. Changes to the background colors of cells in a group-style table view has an effect in iOS 3.0 that is different than previous versions of the operating system. It now affects the area inside the rounded rectangle instead of the area outside of it.
Use the indexPath parameter to achieve the rainbow effect.