UITableView transparent background

I understand that iOS 7 has not been officially released, and we should not discuss it, but I'm going crazy trying to figure this out. On iOS 6, my table view was transparent and looked great. The first launch of iOS 7, and the background is white.

I tried to make table backgroundColor, cell color, etc. for UIColor clearColor, but has no changes.

How to solve this problem?

the table

+88
ios uitableview
Sep 12 '13 at 0:23
source share
21 answers
// 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 your desk has a transparent background (in the storyboard): enter image description here

+120
Sep 12 '13 at 16:40
source share

Put this:

 cell.backgroundColor = [UIColor clearColor]; 

In this section:

 cellForRowAtIndexPath 
+58
Sep 12 '13 at 4:08
source share

This is the answer, but wrong in many ways.

You need to implement the following delegate method:

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

You cannot put the patch in cellForRowAtIndexPath because it is after the cell is displayed and it will flash a white background before the background is cleared (on slower devices).

Use this delegate method and your problems are resolved!

+25
Feb 19 '14 at 5:11
source share

Try setting backgroundView to zero first.

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

Not sure if this documentation change with iOS7 either always has and just hasn’t affected the background color, but the UITableView Reference Reference @property backgroundView

"You must set this property to zero to set the background color as a table."

edit: fixed code syntax

+24
Sep 20 '13 at 19:19
source share

Actually, the officially correct place for changing the background color of a cell differs according to the documentation ( UITableViewCell Class Reference ):

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

+14
Sep 27 '13 at 16:05
source share

This is a pretty nasty problem. Here is my current solution:

Add this to your subclass of UITableViewCell .

 - (void)didMoveToSuperview { [super didMoveToSuperview]; self.backgroundColor = [UIColor clearColor]; } 
+5
Sep 16 '13 at 12:20
source share

This worked for me on iOS7 +:

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

and then in cellForRowAtIndexPath:

 cell.backgroundColor = [UIColor clearColor]; 
+5
Oct 11 '13 at
source share

Swift 3, 4, and 5

 cell.backgroundColor = UIColor.clear 
+5
Nov 16 '15 at 10:18
source share

try this piece of code

 cell.contentView.backgroundColor = [UIColor clearColor]; cell.backgroundColor = [UIColor colorWithWhite:1.0 alpha:0.5]; 
+4
Sep 26 '13 at 15:24
source share

This only worked for me when I edited a clear background color for each cell and a clear color for the table itself. PROGRAMMED

To set a 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() } 

set color for cells:

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCellWithIdentifier("tablecellid", forIndexPath: indexPath) cell.backgroundColor = UIColor.clearColor() return cell } 
+4
Jan 28 '16 at 16:11
source share

One thing is good. UITable color looks white by default (I don't know why)

Background white

But better change that.

+3
Mar 22 '14 at 9:17
source share

First set

 tableView.backgroundColor = [UIColor clearColor]; 

Second set

 tableCell.backgroundColor = [UIColor clearColor]; 
+3
Dec 05 '14 at 8:21
source share

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

in the load view

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

if you want to clear the cell color do it in

 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { cell.backgroundColor = UIColor.clearColor() } 
+3
Mar 05 '16 at 1:19
source share

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

+2
Sep 12 '13 at 0:30
source share

In my case, the cell was created using xib. it looks like the interface builder on xcode5 has problems setting clearColor on cell.backgroundColor.

All I had to do was install

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // get the cell from the nib //then force the backgroundColor cell.backgroundColor = [UIColor clearColor] return cell; } 
+2
Sep 26 '13 at 14:20
source share

Try

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

and

 cell.backgroundColor = [UIColor clearColor]; 
+2
Feb 12 '14 at 20:38
source share

Just select "Clear Color" in the "Background" view for the table and for the cell.

+2
Nov 22 '15 at 13:46
source share

swift 3

 override func viewDidLoad() { super.viewDidLoad() tableView.backgroundColor = UIColor.clear } 
+2
May 7 '17 at 12:40 a.m.
source share
 // Fix iOS 7 clear backgroundColor compatibility // I Think this two lines only are enough cell.backgroundColor = [UIColor clearColor]; cell.selectedBackgroundView = [[UIView new] autorelease]; 
+1
Nov 30 '13 at 10:30
source share

Set

 tableView.backgroundColor = [UIColor clearColor]; 

in viewDidLoad.

If this does not work, try:

 tableView.backgroundView = nil; 
0
Dec 15 '16 at 12:28
source share

In fast 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 } 
0
Dec 26 '16 at 9:36
source share



All Articles