How to create a UITableViewCell with a transparent background

Viewed 74523

I'm trying to set the background color of a UITableViewCell to transparent. But nothing seems to work. I have some images/buttons inside the tableViewCell and I would like to make the white grouptableview background disappear to get a 'floating' effect for the images and buttons (as if they were not inside the tableview).

Any idea how this could be accomplished?

13 Answers

If both the other options didn't work try this

UIView *backView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];
backView.backgroundColor = [UIColor clearColor];
cell.backgroundView = backView;

Start with these articles to get the background color correctly setup:

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 the following lines:

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

There is more than just one view hiding in a UITableViewCell. This should make all of the ones in your way clear.

I had a problem where my custom tableviewcell backgroundimage was overlaid with a white label background, i tried everything and finally setting background to clear color in the 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 rowForCellAtIndexPath 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];
}

There are 3 steps:

  1. cell.contentView.backgroundColor = UIColor.clear
  2. Uncheck opaque check box for table view cell in attributes inspector in Drawing section. This you can find by clicking on the table view cell prototype in storyboard and opening the attribute inspector. Scroll down and you will find it.
  3. Select Background as Clear Color from dropdown at same location as in step 2.
  4. Run your app

Solution for Swift 5.1

let cell = tableView.dequeueReusableCell(withIdentifier: "cellIdentifier", for: indexPath)
cell.backgroundColor = UIColor.clear

After pulling hair out most of my hair, this turned out to be quite simple for xCode 13 / Swift 5.1. There are 2 things that need to be changed.

In your numberOfRowsInSection, add:

tableView.backgroundColor = UIColor.clear

so it looks something like this:

   func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        tableView.backgroundColor = UIColor.clear
        return 40
    }

Then in your cellForRowAt, add:

cell?.backgroundColor = UIColor.clear

so it looks like:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
    cell?.backgroundColor = UIColor.clear
    return cell!
}

Thats it. Couldnt believe my eyes when it worked. :)

I'm late to the party, but will share my findings as they differ from all of the answers here. After spending 2 hours trying out different solutions, I managed to achieve table cell's transparency solely by tweaking two properties in the Interface Builder:

  1. Set the table view background (close to the bottom of the Attributes inspector, in the View section) to Clear Color,
  2. Set the Table View Cell background (again, in the View section) to Clear Color.

I didn't have to change the code, and the additional advantage for those still using the Interface Builder is that the table cell is displayed with transparent (not white) background, which is important when the cell's content items' color is white:

The result

Here is my solution in Swift 4.1:

override func viewDidLoad() {
    super.viewDidLoad()
    tableView.backgroundView = UIImageView(image: "Image")
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    cell.backgroundColor = UIColor.clear
{
Related