Search code examples
iosobjective-cuitableviewuibackgroundcolor

UITableView with scrolling background pattern


I have a UITableView with the backgroundColor property set like so:

tableview.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"IMAGE"]];

This gives the tableview a background, that scrolls, which is exactly what I want.

The problem is, when I add cells to the tableview, in each cell the background pattern of the tableview starts new / starts over:

UIScrollView issue

In the above image, you can see the problem in the red circled areas.

For the tableview cells, I have set all backgroundColors to clearColor for

  • backgroundView
  • textLabel
  • detailedTextlabel
  • contentView

I have also tried to set

cell.backgroundView = [UIView new];
cell.backgroundView.backgroundColor = [UIColor clearColor];

and the same for the contentView, too.

Additional Note: Setting the backgroundView of the tableview does not help, since then the background does NOT scroll anymore!


Solution

  • Just ran into this issue and found this fixes the cell having it's own copy of the backgroundColor

    - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
        [cell setBackgroundColor:[UIColor clearColor]];
    }