Uitableview Backgroundcolor Always White on iPad

UITableView backgroundColor always white on iPad

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.

UITableView backgroundColor always gray on iPad

Try one of these.

[myTableView setBackgroundView:nil];
[myTableView setBackgroundView:[[[UIView alloc] init] autorelease]];

Static UITableViewCell backgroundColor always white on iPad

You should set the cell.contentView.backgroundColor, as @SandeepAggarwal has pointed out.

UITableViewCell show white background and cannot be modified on iOS7

As Apple DOC said (UITableViewCell Class Reference):

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

So for my case that to show cells with transparent background, just need to implement the delegate method in the table view controller like below:

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

Just Note: As @null said, "...there seems to be a bug in interface builder...", I'm not totally sure whether it does have the bug, but seems so cause his comment got several up votes. So there might something wrong if you use IB. :)

Programmatically created UITableView always white in iOS9

init method is not a good place to modify UI properties because the view hierarchy hasn't been constructed yet.

Try using layoutSubviews or didMoveToWindow for UIView subclasses:

var customColor = UIColor.yellowColor()
override func layoutSubviews() {
super.layoutSubviews()
self.backgroundColor = customColor
}

override func didMoveToWindow() {
super.didMoveToWindow()
self.backgroundColor = customColor
}

You can also use viewDidLoad or awakeFromNib methods in UIViewController subclasses:

override func viewDidLoad() {
super.viewDidLoad()
customTableView.backgroundColor = UIColor.yellowColor()
}

override func awakeFromNib() {
super.awakeFromNib()
customTableView.backgroundColor = UIColor.yellowColor()
}

Unable to change background color of static table view cell on iOS 7 (iPad)

Do this:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIImage *pattern = [UIImage imageNamed:@"image.png"];
[cell setBackgroundColor:[UIColor colorWithPatternImage:pattern]];
}

Work for me on IOS7

Container View White Background, iPad Swift Issue

This was basically a solution to my problem, only thing I had to add and I will attach the swift code was "willDisplayCell" method using tableViewDelegate.

override func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
var backgroundView : UIView = UIView(frame: CGRect.zeroRect)
backgroundView.backgroundColor = UIColor.clearColor()
cell.backgroundView = backgroundView
cell.backgroundColor = UIColor.clearColor()
}

How to add a white view under cell in to the UITableView?

You mentioned above that there are UIView elements on your UITableView background so setting he background color of it would not work, correct?

You could try setting the background color of the UITableViewCell itself, and add any of your custom views as subviews on the cell.

cell.backgroundColor = [UIColor whiteColor];

UITableView is resetting its background color before view appears

I ended up moving the initialization to lazy var's function – turns out initializing UITableView during the initialization of it's view controller has some side effects.



Related Topics



Leave a reply



Submit