UITableView fondo claro

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.

¿Cómo arreglar este problema?

la mesa

preguntado el 12 de septiembre de 13 a las 01:09

Tried setting the table's backgroundView to a clear one? -

Could you show the code where you are setting the background colour? What about the parent view? Perhaps the table view background is clear but the parent isn't? -

I noticed this same thing but when I installed the same app that predated my current version to iOS 7.0 it wasn't happening. Does this problem lie in xCode5.0 then? -

21 Respuestas

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

en cellForRowAtIndexPath

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

Respondido 18 ago 14, 21:08

George, add that code inside the method - (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath - Ian Stallings

For the cases, if you really need selectedBackgroundView, you can put the following in cellForRowAtIndexPath: cell.selectedBackgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"yourBgImage.png"]] autorelease]; or even in awakeFromNib: self.selectedBackgroundView = ... Note, that: self.backgroundColor = [UIColor clearColor]; does not work in awakeFromNib under iOS7. But: cell.backgroundColor = [UIColor clearColor]; works properly only in cellForRowAtIndexPath for iOS 7.0 - golpe

Only need to add the row: cell.backgroundColor = [UIColor clearColor]; - evya

This works like charm cell.backgroundColor = [UIColor clearColor]; - bpolat

¿Cómo hacer esto en Swift? - qadir hussein

Pon esto:

cell.backgroundColor = [UIColor clearColor];

En esta sección:

cellForRowAtIndexPath

Respondido el 12 de Septiembre de 13 a las 12:09

In iOS 6, it is sufficient to set the backgroundView to an empty view, but this additional code is needed for iOS 7. - fronteras de kevin

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

Respondido 13 Feb 14, 17:02

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!

Respondido 19 Feb 14, 05:02

Yes. For iOS 7 this is the way to clear the background. All the other suggestions above might not work. - girish_vr

Actually the officially correct place to change cell background color is different according to documentation (Referencia de la clase UITableViewCell):

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.

Respondido el 27 de Septiembre de 13 a las 17:09

I am trying this, but the very first cells shown all have a white background. If I create new cells by scrolling, then they will have the transparent background I want. Not sure what else to try… - david dunham

Never mind, it appears to be a timing issue. I was doing stuff in awakeFromNib, which was too early. - david dunham

swift 3, 4 and 5

cell.backgroundColor = UIColor.clear

Respondido 30 Abr '19, 13:04

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

Agregue esto a su UITableViewCell subclase.

- (void)didMoveToSuperview {
    [super didMoveToSuperview];

    self.backgroundColor = [UIColor clearColor];
}

Respondido el 16 de Septiembre de 13 a las 13:09

Oh god. Thank you. Saved my night. Your answer should have been the accepted one. - Michal Shatz

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
}

Respondido el 28 de enero de 16 a las 16:01

This worked for me in iOS7+:

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

y luego en cellForRowAtIndexPath:

cell.backgroundColor = [UIColor clearColor];

Respondido 25 Abr '16, 07:04

prueba este fragmento de código

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

Respondido el 26 de Septiembre de 13 a las 16:09

Primer set

tableView.backgroundColor = [UIColor clearColor];

Segundo juego

tableCell.backgroundColor = [UIColor clearColor];

Respondido el 05 de diciembre de 14 a las 08:12

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

Background white

But better change that.

respondido 22 mar '14, 09:03

Perfect! That was the missing peace. No additional line of code needed! - Morpheus78

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() 

}

respondido 05 mar '16, 01:03

In my app, I had to set the backgroundColor en mi UITableViewCell clase de [UIColor clearColor] color when I updated for iOS 7.

Respondido el 12 de Septiembre de 13 a las 12:09

Trata

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

Y

cell.backgroundColor = [UIColor clearColor];

Respondido 12 Feb 14, 20:02

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;
}

Respondido 18 ago 14, 21:08

control reaches end of non-void function - cuerda

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

respondido 22 nov., 15:13

Swift 3

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

contestado el 07 de mayo de 17 a las 01:05

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

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

respondido 30 nov., 13:10

En 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
}

Respondido el 26 de diciembre de 16 a las 09:12

Working for me...... - M Hamayun zeb

Kit

tableView.backgroundColor = [UIColor clearColor];

en viewDidLoad.

if this is not working, try:

tableView.backgroundView = nil;

Respondido el 15 de diciembre de 16 a las 12:12

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.