Set 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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…