There are currently a lot of answers on how to set a custom fixed background for a UITableView. But is there any trick to make the background image scroll together with the table cells?
Thanks!
There are currently a lot of answers on how to set a custom fixed background for a UITableView. But is there any trick to make the background image scroll together with the table cells?
Thanks!
You have to set the background image via backgroundColor property of UITableView:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
.
UIImageView *background = [[UIImageView alloc]initWithImage: [UIImage imageNamed: @"background.jpg"]];
[tableView addSubview: background];
[tableView sendSubviewToBack: background];
I would think that the answer is to subclass the UITableView and override layoutSubviews. In the UITableView you should make a property that points to a background UIImageView.
When you override layoutSubviews just write
-(void) layoutSubviews {
[self sendSubviewToBack: backgroundImageView];
[super layoutSubviews];
}
This answer could also be helpful. Background image that's scrollable and in synch with the UITable scrolling
It involves a bit of trickery with Table Views.
You have to create a separate background table that is a slave of your foreground table, and it uses KVO to listen to the foreground table view's contentOffset property.
A possible answer was -- obviously -- already on stackoverflow:
self.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"desk.png"]];
Ref: iPhone - Setting background on UITableViewController
Edit: That's not a perfect answer, I know :)