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!

有帮助吗?

解决方案

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]];
}

其他提示

Here is what I would do:

1) Create a view controller and set the view background color to your pattern image.

2) Add your table view controller as a child view controller to the newly created view controller. This can be done in code or if you are using iOS 6 and storyboards, with an embed segue. If you are doing it in code you may need to set the frame of the table view controller manually.

3) Set the background color of your table view controller to [UIColor clearColor]

I had a similar issue and this is what worked for me.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top