Transparent UITableViewCell for a grouped UITableView?

I would like to create a table cell of a TRANSLUCENT grouped table. In other words, I want to see the background image of a grouped table, but I do not want to completely clear the cells. I saw many questions about transparent cells, but not a single address did translucent (only partially transparent) cells.

Here is what I am trying:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.contentView.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.5f]; cell.backgroundColor = [UIColor clearColor]; cell.backgroundView.backgroundColor = [UIColor clearColor]; } 

And this is the result: enter image description here

This is almost correct, except that the contentView of the cell extends beyond the rounded corners of the grouped cell.

SOLVED using a transparent image and setting the background representation of the cell. It would be all the same to love to do this programmatically, although if someone has a solution, I will gladly accept it.

SOLVED Part II You can also do this by setting the backgroundView to a new UIView that has the desired background color and rounded corners through a call to QuartzCore setCornerRadius for the view layer property.

+4
source share
2 answers

For someone else wondering, the code I used was:

 - (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { //... cell.contentView.backgroundColor = [UIColor clearColor]; cell.backgroundColor = [UIColor clearColor]; UIView *bgView = [[UIView alloc] init]; [[bgView layer] setCornerRadius:10.0f]; [bgView setBackgroundColor:[UIColor colorWithWhite:1.0f alpha:0.25f]]; cell.backgroundView = bgView; //... return cell; } 
+3
source

That should be all you need:

 cell.contentView.backgroundColor = [UIColor clearColor]; cell.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5]; 
+3
source

All Articles