简体   繁体   中英

Scrolling background image for UITableView?

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!

您必须通过UITableView的backgroundColor属性设置背景图像:

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 :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM