Matt Rees
Matt Rees

Reputation: 884

iOS 8.1 UITableview Background Colour always white

So I've tested this in iOS 7.1 and it works fine. I'm setting the background colour to clear on my tableview using the lines below.

    self.tableview = [[UITableView alloc]initWithFrame:self.bounds style:UITableViewStylePlain];
    self.tableview.delegate = self;
    self.tableview.dataSource = self;
    self.tableview.backgroundView = nil;
    self.tableview.backgroundColor = [UIColor clearColor];
    self.tableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];
    [self addSubview:self.tableview];

I'm also setting the tableFooterView to a new view to hide any left over unused cells using.

self.tableview.tableFooterView = [[UIView alloc]initWithFrame:CGRectZero];

This works beautifully on iOS 7 but in iOS 8 I'm left with a white background colour for the space under the tableview. The superview the tableview sits inside also has a background colour of clear. Any ideas?

Added images below - I've had to obscure the client name

Working on iOS 7 Working on iOS 7

Not working on iOS 8.1enter image description here

Upvotes: 7

Views: 2529

Answers (2)

MLQ
MLQ

Reputation: 13511

For me, this is what worked (I am using a custom UITableViewCell in its own XIB):

  • Set the cell's content view background to clear color in IB.
  • Set the cell's background to clear color in IB.
  • Set the table view's background color to UIColor.clearColor() programatically in viewDidLoad. Doing it in the Storyboard doesn't work.

Upvotes: 0

neerajPK
neerajPK

Reputation: 293

Apple document says

... 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.

You might need to use willDisplayCell UITableView delegate method to have a transparent background for your table view .

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cellforRowAtIndexPath:(NSIndexPath *)indexPath

{
      [cell setBackgroundColor:[UIColor clearColor]];
}

Upvotes: 4

Related Questions