Last Updated: January 28, 2019
·
2.848K
· sage042

Create a scrolling background pattern for UITableView

If you want the background pattern image to scroll with a UITableView, you can set the backgroundColor.

UIImage *image = [UIImage imageNamed:@"pattern.png"];
UIColor *bgPattern = [UIColor colorWithPatternImage:image];
[tableView setBackgroundColor:bgPattern];

Now that the background is set, you'll notice that any UITableViewCells that are added to the table will contain their own copy of the pattern. To remove the cell's autoformatting you'll need to catch the cell after it has been created with the following delegate method.

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

1 Response
Add your response

you saved me! thanks a lot!

over 1 year ago ·