Daniel Carneiro
Daniel Carneiro

Reputation: 65

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 tried 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];

Upvotes: 0

Views: 727

Answers (3)

Dee
Dee

Reputation: 1897

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.

Upvotes: 1

vfn
vfn

Reputation: 6066

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.

Upvotes: 3

Rasika
Rasika

Reputation: 1998

cell.background-color: transparent; with the page background-color set to black?

Upvotes: 0

Related Questions