Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView backgroundColor always white on iPad

I'm working on a project. I have plenty of UITableViews which are set as clear color. Their views' background color are set to my custom color and everything is fine on iPhone.

The issue comes up on iPad! I tried almost everything, but my UITableView has a white color.

I checked the other topics, like: UITableView backgroundColor always gray on iPad, but nothing worked. Also, my problem is not grey, it's white as snow!

What might be the reason of it?

like image 662
Göktuğ Aral Avatar asked Dec 18 '14 16:12

Göktuğ Aral


2 Answers

Good News: According to the release notes, for iOS 10:

When running on iPad, the background color set for a UITableViewCell in a Storyboard is now respected.

For versions <10:

I was seeing this in iOS 8 (8.3). Even though in IB my cells were "clear color" and their content views were "clear color" they would render as white. An imperfect but reasonable solution, since it still takes values from IB:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {     ...     cell.backgroundColor = cell.contentView.backgroundColor;     return cell; } 

It seems that my dequeued reuseable cells get their background forced to white on iPad. I was able to determine this using the view hierarchy debugger.

Once I did this I was able to use the table's background color and didn't have to set a background view, although that works as well.

like image 78
Ben Flynn Avatar answered Oct 06 '22 22:10

Ben Flynn


You can fix this by making an appearance API setting in your appDelegate file :

Swift:

UITableViewCell.appearance().backgroundColor = UIColor.clearColor() 
like image 40
Kiko Lobo Avatar answered Oct 06 '22 23:10

Kiko Lobo