How to set the background color of a cell to a tinted black color
I want to set the color
of the cell
to a transparent black. How can I do that?
I 开发者_如何学JAVAtried to set the alpha
to .5 but it doesn't work.
cell.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5];
On the UITableViewCell
Class Reference, there is the following note:
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 byUIView
) you must do it in thetableView:willDisplayCell:forRowAtIndexPath:
method of the delegate and not intableView: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.
So, put the code cell.backgroundColor = [UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5];
on the right place and it should work as you want.
Another option is to set a background view for you cell, with the selected color or gradient.
set the cell background color in 'willDisplayCell
' delegate method of the tableView.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
[cell setBackgroundColor:[UIColor colorWithRed: 0.1 green: 0.1 blue: 0.1 alpha: 0.5]];
}
It will work now. Check It.
cell.background-color: transparent;
with the page background-color
set to black?
精彩评论