tags:

views:

205

answers:

2

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

A: 

I bet your text is an opaque UILabel. I remember having to add myText.backgroundColor = [UIColor clearColor] to the content text UILabel to get this to work right.

Squeegy
Thanks sounds like a promising root to the solution. I have tried what you suggested (see updated code sample above), but still no joy, any suggestions?
tigermain
Can you post a screenshot?
Squeegy
Not easily no as Im a bit of a mac newb, but Im sure it is what you suggest. I think the label is simply not opaque. But as you can see above Im trying all I can think of. Have I missed something obvious?
tigermain
A: 

I have managed to do it using a Custom TableViewCell object, but Im sure there must be a way to do it without

tigermain