I have gone as far as to use the following code to set the background colour of a TableView cell (in cellForRowAtIndexPath)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor = [UIColor yellowColor];
cell.contentView.backgroundColor = [UIColor yellowColor];
UIView* backgroundView = [ [ [ UIView alloc ] initWithFrame:CGRectZero ] autorelease ];
backgroundView.backgroundColor = [ UIColor yellowColor ];
cell.backgroundView = backgroundView;
for ( UIView* view in cell.contentView.subviews )
{
view.backgroundColor = [ UIColor yellowColor ];
}
}
// Set up the cell...
if ([[menuList objectAtIndex:indexPath.row] isKindOfClass:[Category class]])
{
cell.text = ((Category *)[menuList objectAtIndex:indexPath.row]).name;
}
else
{
[cell setText: [menuList objectAtIndex:indexPath.row]];
}
return cell;
}
However when it renders only part of the cell has the background applied kind of like this (where z is the bg fill), even the background of the Accessory is colour but not the text.
xxxxxxxxxxxxxxxxxxxx
zzzSearch
xxxxxxxxxxxxxxxxxxxx
The only way I see to be able to change the background of the text is by setting the background colour of the whole table view in Interface Builder