滚动UITableView的背景图片?

时间:2009-07-13 12:34:51

标签: iphone cocoa-touch uitableview

目前有很多关于如何为UITableView设置自定义固定背景的答案。但有什么技巧可以让背景图像与表格单元一起滚动 吗?

谢谢!

5 个答案:

答案 0 :(得分:7)

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

self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];

答案 1 :(得分:3)

UIImageView *background = [[UIImageView alloc]initWithImage: [UIImage imageNamed: @"background.jpg"]];
    [tableView addSubview: background];
    [tableView sendSubviewToBack: background];

答案 2 :(得分:3)

我认为答案是继承UITableView并覆盖layoutSubviews。在UITableView中,你应该创建一个指向背景UIImageView的属性。

当您覆盖layoutSubviews时,只需编写

-(void) layoutSubviews {
    [self sendSubviewToBack: backgroundImageView];
    [super layoutSubviews];

}

答案 3 :(得分:0)

这个答案也可能有所帮助。 Background image that's scrollable and in synch with the UITable scrolling

它与表视图有点诡计。

您必须创建一个单独的后台表,它是前台表的从属,它使用KVO来监听前台表视图的contentOffset属性。

答案 4 :(得分:-6)

一个可能的答案 - 显然 - 已经在stackoverflow:

self.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"desk.png"]];

参考:iPhone - Setting background on UITableViewController

编辑:这不是一个完美的答案,我知道:)。

相关问题