Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableView Background Image
    text
    copied!<p>I am trying to set up a table view with a background that scrolls. The background is a repeating cloud image.</p> <p>As a preliminary attempt to implement this, I have used the following code:</p> <pre><code>- (void)viewDidLoad { aTableView.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]]; aTableView.separatorStyle = UITableViewCellSeparatorStyleNone; } </code></pre> <p>However, this does not quite work as I had hoped. The image is placed as the background to every cell (which is fine) but also as the background to the table view, so that when the user scrolls past the bounds of the screen and the bounce is used, the same cloud background is shown. This gives an undesired overlapping effect.</p> <p>What I would like is for every cell to have this repeating image (so that it scrolls with the table), but for the background to the table view to be a plain black colour. Is this possible? </p> <p>I know that I can add an image to the custom cell and send it to the back, but this seems like too much of a memory hogging workaround.</p> <p>Cheers</p> <hr> <p>I have managed to sort this using the following code:</p> <pre><code>- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { [cell setBackgroundColor:[UIColor colorWithPatternImage: [UIImage imageNamed: @"cloud.jpg"]]]; } </code></pre> <p>Is this the best way to set a UIColor as a UIImage or is this resource intensive?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload