UITableView clear background

IosUitableview

Ios Problem Overview


I realize that iOS 7 has not officially been released and we should not discuss it BUT I am going crazy trying to figure out this problem. On iOS 6, my table view was transparent and looked great. First time running iOS 7, and the background is white.

I have tried making the table backgroundColor, cell color etc etc to UIColor clearColor but have no change.

How to fix this problem?

the table

Ios Solutions


Solution 1 - Ios

    // Fix for iOS 7 to clear backgroundColor
    cell.backgroundColor = [UIColor clearColor];
    cell.backgroundView = [[UIView new] autorelease];
    cell.selectedBackgroundView = [[UIView new] autorelease];

in cellForRowAtIndexPath

Also, make sure that your tableview actually has transparent background (in storyboard): enter image description here

Solution 2 - Ios

Put this:

cell.backgroundColor = [UIColor clearColor];

In this section:

cellForRowAtIndexPath

Solution 3 - Ios

Try setting backgroundView to nil first.

[self.tableView setBackgroundView:nil];
[self.tableView setBackgroundColor:[UIColor clearColor]];

Not sure if this is a change in documentation with iOS7 or has always been there and just did not affect background color, but per UITableView Class Reference @property backgroundView

"You must set this property to nil to set the background color of the table view."

edit: corrected code syntax

Solution 4 - Ios

This has been answered, but incorrectly in a lot of ways.

You need to implement the below delegate method:

    - (void)tableView:(UITableView *)tableView  willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [cell setBackgroundColor:[UIColor clearColor]];
}

You can't put the fix in cellForRowAtIndexPath because that is after the cell is rendered, and it will flash a white background before the background gets set to clear (on slower devices).

Use this delegate method and your problems are solved!

Solution 5 - Ios

Actually the officially correct place to change cell background color is different according to documentation (UITableViewCell Class Reference):

> Whether you use a predefined or custom cell, you can change the cell’s > background using the backgroundView property or by changing the > inherited backgroundColor property. In iOS 7, cells have a white > background by default; in earlier versions of iOS, cells inherit the > background color of the enclosing table view. If you want to change > the background color of a cell, do so in the > tableView:willDisplayCell:forRowAtIndexPath: method of your table view > delegate.

Solution 6 - Ios

swift 3, 4 and 5

cell.backgroundColor = UIColor.clear

Solution 7 - Ios

This is quite a frustrating problem. Here's my current solution:

Add this to your UITableViewCell subclass.

- (void)didMoveToSuperview {
    [super didMoveToSuperview];

    self.backgroundColor = [UIColor clearColor];
}

Solution 8 - Ios

This worked for me in iOS7+:

self.tableView.backgroundColor =[UIColor blueColor];
self.tableView.opaque = NO;
self.tableView.backgroundView = nil;`

and then in cellForRowAtIndexPath:

cell.backgroundColor = [UIColor clearColor];

Solution 9 - Ios

This did only work for me when i edited a clear background color for each cell and a clear color for the table itself.. BOTH PROGRAMMATICALLY

to set the clear color for the table:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    initMenu()
    myTableView.backgroundColor = UIColor.clearColor()
}

to set the color for the cells:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCellWithIdentifier("tablecellid", forIndexPath: indexPath)
    cell.backgroundColor = UIColor.clearColor()
    return cell
}

Solution 10 - Ios

try this code snippet

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

Solution 11 - Ios

One thing to nice. The default color of UITable seems to be white (I don't know why)

Background white

But better change that.

Solution 12 - Ios

First set

tableView.backgroundColor = [UIColor clearColor];

Second set

tableCell.backgroundColor = [UIColor clearColor];

Solution 13 - Ios

create IB Outlet for table view @IBOutlet weak var yourTable : UITableView!

in view load

override func viewDidLoad() {
    yourTable.delegate = self
    yourTable.dataSource = self
    
    yourTable.backgroundColor = UIColor.clearColor()
}

if you want to clear color of Cell also do this in

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
 
    cell.backgroundColor = UIColor.clearColor() 

}

Solution 14 - Ios

In my app, I had to set the backgroundColor on my UITableViewCell class to [UIColor clearColor] color when I updated for iOS 7.

Solution 15 - Ios

In my case the cell was created using a xib. it seems like interface builder on xcode5 has trouble setting clearColor to the cell.backgroundColor.

All I needed to do was indeed to set

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// get the cell from the nib
//then force the backgroundColor
cell.backgroundColor = [UIColor clearColor]
return cell;
}

Solution 16 - Ios

Try

[myTable setSeparatorStyle:UITableViewCellSeparatorStyleNone];
[myTable setSeparatorInset:UIEdgeInsetsZero];

And

cell.backgroundColor = [UIColor clearColor];

Solution 17 - Ios

Just select Clear Color on View Background for the table and for the cell also.

Solution 18 - Ios

swift 3

override func viewDidLoad() {
        super.viewDidLoad()
        tableView.backgroundColor = UIColor.clear
}

Solution 19 - Ios

// Fix iOS 7 clear backgroundColor compatibility 
// I Think this two lines only are enough

cell.backgroundColor = [UIColor clearColor];
cell.selectedBackgroundView = [[UIView new] autorelease];

Solution 20 - Ios

In swift 3

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "CustomCell", for: indexPath)
    cell.backgroundColor = .clear
    cell.backgroundView = UIView()
    cell.selectedBackgroundView = UIView()
    return cell
}

Solution 21 - Ios

Set

tableView.backgroundColor = [UIColor clearColor];

in viewDidLoad.

if this is not working, try:

tableView.backgroundView = nil;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTeddy13View Question on Stackoverflow
Solution 1 - IosslamorView Answer on Stackoverflow
Solution 2 - IosMaximus VermillionView Answer on Stackoverflow
Solution 3 - IosdandanView Answer on Stackoverflow
Solution 4 - IosedhnbView Answer on Stackoverflow
Solution 5 - IosasdusdView Answer on Stackoverflow
Solution 6 - IosJamal alaayqView Answer on Stackoverflow
Solution 7 - IosBerkView Answer on Stackoverflow
Solution 8 - IosDevCView Answer on Stackoverflow
Solution 9 - IosSoliQuiDView Answer on Stackoverflow
Solution 10 - IosStornu2View Answer on Stackoverflow
Solution 11 - IosPaul BrewczynskiView Answer on Stackoverflow
Solution 12 - IosFantasyczlView Answer on Stackoverflow
Solution 13 - Iosveenaay pawarView Answer on Stackoverflow
Solution 14 - IosArthur DexterView Answer on Stackoverflow
Solution 15 - IosBen GView Answer on Stackoverflow
Solution 16 - IosJorgyView Answer on Stackoverflow
Solution 17 - IosWalter BarletView Answer on Stackoverflow
Solution 18 - IosBenjamin RDView Answer on Stackoverflow
Solution 19 - IosKiran JasvaneeView Answer on Stackoverflow
Solution 20 - IosPatricio BravoView Answer on Stackoverflow
Solution 21 - IosLal KrishnaView Answer on Stackoverflow