Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView background color

I've seen various posts on background color for a UITableView for ios 4.2 but I just cannot seem to change the background color.

UIView *bgView = [[[UIView alloc] init] autorelease];
bgView.backgroundColor = [UIColor blackColor];
bgView.opaque = YES;
self.myTableView.backgroundView = bgView;

I've placed this code in a viewDidLoad but it won't change colors. My UITableView is an IBOutlet inside a UIViewController with a UITableViewDelegate & UITableViewDataSource so I'm thinking at the viewDidLoad the UITableView is already rendered and I cannot change its background color.

EDIT * - the UITableView is grouped

like image 749
fes Avatar asked Jul 17 '11 13:07

fes


People also ask

How do I change the background color of a Tableview?

For changing the background color of the table view cell, you should change the contentView. backgroundColor property of the cell. Now run the project to see the effect.


2 Answers

Try setting the background view of the table view to nil and also set the background colour of the table view

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.myTableView.backgroundView = nil;
    self.myTableView.backgroundColor = [UIColor blackColor];
}
like image 176
Edward Huynh Avatar answered Sep 21 '22 18:09

Edward Huynh


Simply changee the backgroundColor property of both tableView and tableView's backgroundView.

- (void)viewDidLoad {
    [super viewDidLoad];

   id desiredColor = [UIColor clearColor];
   self.tableView.backgroundColor = desiredColor;
   self.tableView.backgroundView.backgroundColor = desiredColor;
}
like image 45
Michal K. Avatar answered Sep 19 '22 18:09

Michal K.