Change background of a UITableViewCell
I was asked this question by a co-worker on how to do this. My first answer was when you init the cell just set the backgroundColor but that did not work at all.
If you followed my other tutorials and have a custom UITableViewCell open that file and in the initWithFrame method you want the following
MyContentView.backgroundColor = [UIColor redColor];
Is anything besides setting the background to another color? Like setting the background to a certain image? Just like themes…
Did you manage to do this as I am trying to do the same.
Existing code:
self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
I am trying to replace the background colour with a picture.
Thanks for any help
Just create new UIView, set it as table cell backgroundView and use backgroundColor of this UIView.
Don’t set the background color when the cell is created as the color is controlled at that point by the table. Rather implement the delegate method and set the background color there. Very easy this way.
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1) {
[cell setBackgroundColor:[UIColor yellowColor]];
}
}
I see, I spuopse that would have to be the case.