How to create a UITableViewCell with a transparent background

I am trying to make the background color of a UITableViewCell transparent. But nothing works. I have some images / buttons inside a tableViewCell , and I would like the white background of the grouptableview disappear in order to get a “floating” effect for the images and buttons (as if they were not inside the tableview ).

Any idea how this can be done?

+66
iphone cocoa-touch uitableview
Jun 17 '09 at 16:43
source share
8 answers

If both other options do not work, try this

 UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; backView.backgroundColor = [UIColor clearColor]; cell.backgroundView = backView; 
+120
Jun 18 '09 at 0:13
source share

This actually answers in UITableViewCell docs. Therefore, when you need to adjust the transparency of your controls, the actual background color of the cell should be set below.

"Note: If you want to change the background color of the cell (by setting the background color of the cell via the backgroundColor property declared by UIView), you must do this in tableView: willDisplayCell: forRowAtIndexPath: delegate method and not in tableView: cellForRowAtIndexPath: data source. Changes in background colors cells in the group style table view affect iOS 3.0, which is different from previous versions of the operating system. Now it affects the area inside the rounded rectangle instead of the area outside it. "

https://developer.apple.com/documentation/uikit/uitableviewcell

+39
Oct 21 '10 at 20:36
source share

Start with these articles to properly set the background color:

http://howtomakeiphoneapps.com/2009/03/how-to-add-a-nice-background-image-to-your-grouped-table-view/

http://pessoal.org/blog/2009/02/25/customizing-the-background-border-colors-of-a-uitableview/

Then try all of the following lines:

 [[cell contentView] setBackgroundColor:[UIColor clearColor]]; [[cell backgroundView] setBackgroundColor:[UIColor clearColor]]; [cell setBackgroundColor:[UIColor clearColor]]; 

In UITableViewCell, only one view is hidden more. This should make everything in your way understandable.

+30
Jun 17 '09 at 18:04
source share
 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor clearColor]; cell.backgroundView.backgroundColor = [UIColor clearColor]; } 
+24
Nov 14 '11 at 17:55
source share

I have a simple solution

Objective-c version:

 cell.backgroundColor = [UIColor clearColor]; 

Swift version :

 cell.backgroundColor = UIColor.clearColor() 
+16
Feb 04 '14 at 11:07
source share

By default, the background of your UITableViewCell is white. Doing myCell.backgroundColor = [UIColor clearColor]; will make your UITableViewCell transparent, but you won’t feel the difference, because the UITableView (the creator of your UITableViewCell) also has a white background by default.

If you want to see your UIView background, you need to make the transparency of your cell and your table:

 myTableView.backgroundColor = [UIColor clearColor]; myTableCell.backgroundColor = [UIColor clearColor]; 

Martin Magakyan

+11
Aug 24 2018-11-11T00: 00Z
source share

If you are using storyboards, be sure to uncheck the box “Opaque” for your prototype UITableViewCells

+3
Oct 24 '14 at 18:01
source share

I had a problem when my custom tableviewcell wallpaper was overlaid on a white shortcut label, I tried everything and finally set the background to clear the color in viewWillAppear did the trick.

  - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; self.tableView.backgroundColor = [UIColor clearColor]; // if this is not here, cell background image is covered with a white rectangle :S } 

and in the line ForCellAtIndexPath I set the background image:

  if(!cell) { cell = [[[UITableViewCell alloc] initWithFrame: ... UIImageView *cellBG = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellbg.jpg"]]; [cell setBackgroundView:cellBG]; [cellBG release]; } 
+2
Jul 27 '09 at 6:42
source share



All Articles