Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background of a grouped UITableView

I'm having some trouble trying to change the background of a UITableView with groups.

_tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableViewBg.png"]];

This usually works on every other UITableView, but not the one with groups, is there something else I have to do? In IB I have the background color set to a clear color, but that doesn't do much.

like image 557
woutr_be Avatar asked Jun 15 '12 08:06

woutr_be


4 Answers

You additionally need to disable the background view of _tableView:

[_tableView setBackgroundView:nil];
 _tableView.backgroundColor = [UIColor redColor];

No need to add new view to backgroundView. This is working for me in iOS6.

like image 92
Nirav Jain Avatar answered Oct 16 '22 12:10

Nirav Jain


why don't you set the tableView.backgroundView? you can alloc an image view withe the specified image and pass it to the background view instead of setting the background color.

like image 38
Siam Avatar answered Oct 16 '22 11:10

Siam


What I usually do with grouped UITableViews is set the background color to clear, and the set that pattern image to the parents view.

self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tableBG.png"]];
self.tableView.backgroundColor = [UIColor clearColor];
like image 3
Adam Flatau Avatar answered Oct 16 '22 11:10

Adam Flatau


tableView.backgroundView = nil;
tableView.backgroundColor = [UIColor colorWithPatternImage: xxx];
// tableView.backgroundColor = [UIColor redColor];  // is ok

if you set set the backgroundColor as this, when you scroll the tableView, the backgroundColor view will scroll also. so, you can: tableView.backgroundView = nil; self.view.backgroundColor = ...

like image 1
勇敢的心 Avatar answered Oct 16 '22 11:10

勇敢的心