I have an image which height is about 1,5 screen on iPhone. I want to make it as a continuous background of UITableView. It have to scroll with the table. Is there any way to do it?
You could turn this image into a pattern that can then be repeated indefinitely as the background of the table view. First, do this:
UIColor *backgroundPatternColor = [UIColor colorWithPatternImage:myImage];
Then set the background color of your table view, or any other view for that matter, to backgroundPatternColor.
There is simple solution.
Use this code to set background pattern image for table view (pattern image may be small image, which you would like to tile):
- (void)viewDidLoad
{
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"back"]];
}
Tiled image will be tiled infinite both up and down and scrolled with tableView.
Then do next important trick - set transparent background color to cells, because setting tableView backgroundColor also sets tiled backgrounds to cells:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.backgroundColor = [UIColor clearColor];
}
Use this approach for simple tableView cells, otherwise transparent backgrounds of complex cells yields performance lack.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With