开发者

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 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.

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?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜