rodrigochousal rodrigochousal - 3 months ago 20
iOS Question

Unable to make UITableViewCell have clear color

This is very straightforward. I've tried this a couple of times, in both


Here is my code:

cell.alpha = 0.0
cell.backgroundView?.alpha = 0.0
cell.contentView.alpha = 0.0
cell.backgroundView?.backgroundColor = UIColor.clear
cell.backgroundColor = UIColor.clear
cell.contentView.backgroundColor = UIColor.clear

I'm pretty sure this should be overkill, but I'm having a really hard time making this work. The cells are being modified inside an if statement because this only applies to certain cells. Yes, I've checked, and the if statement is working as expected. Any ideas?

I am using Xcode version 8.2 beta


You should set:

cell.backgroundColor = .clear

and also you should provide clear color for whole tableView:

tableView.backgroundColor = .clear

I've tested in sample project. I create UIViewController with UITableView. Set the .red color for view of UIViewController. Create UITableView, apply .clear color for cell and tableView. You should see the red colored background - so the cells and tableView are transparent.

Here are example screen(The label is added to .view of UIViewController to make sure that tableView is transparent):

enter image description here