Why doesn\'t UITableViewCell background color work (set in interface builder)?
I note from some searching that the follow code set in your custom subclass of UITable
It works perfectly, if you pick the tableview and set background to for example red the whole table will be red. maybe you do not linked the table or something
hope it helped
Trying to set the background colour of the UITableViewCell itself is not how you should be doing it. A table cell has a collection of five useful views you can access, one of which is backgroundView
.
Recommended reading:
http://cocoawithlove.com/2009/04/easy-custom-uitableview-drawing.html
and then:
http://cocoawithlove.com/2010/12/uitableview-construction-drawing-and.html
(try this)
Apple's IB's design is generic to be applied to multiple kinds of components, and is also targeted at a highly technical audience (developers). Hence it has not been designed (as an application) to fully customise the interface properly for each component/situation type. So in this case it is the case the ability to seemingly set the background-color is somewhat misleading.
What worked for me is creating my own UIView object to be set as the background view of the UITableViewCell. In the cellForRowAtIndexPath:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIView* bgview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 1)];
bgview.opaque = YES;
bgview.backgroundColor = [UIColor orangeColor];
[cell setBackgroundView:bgview];
It's a bit late, but I just ran into this issue... Setting the background color on the contentView
works fine:
cell.contentView.backgroundColor = [UIColor redColor];
Try this it works for me:
- (void)tableView:(UITableView *)tableView1 willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[cell setBackgroundColor:[UIColor clearColor]];
tableView1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"Cream.jpg"]];
}