Iphone UITableView部分背景?

Iphone UITableView部分背景?,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,是否可以在UITableView中的某个部分后面使用背景图像 我想不出如何实现这一点。您可以在表视图后面放置一个视图,将表视图的背景颜色设置为[UIColor clearColor],然后您将看到后面的视图 [self.view addSubview:self.sectionBackgroundView]; [self.view addSubview:self.tableView]; self.tableView.backgroundColor = [UIColor clearColor];

是否可以在UITableView中的某个部分后面使用背景图像


我想不出如何实现这一点。

您可以在表视图后面放置一个视图,将表视图的背景颜色设置为[UIColor clearColor],然后您将看到后面的视图

[self.view addSubview:self.sectionBackgroundView];
[self.view addSubview:self.tableView];
self.tableView.backgroundColor = [UIColor clearColor];
这样做的缺点是,这将不仅限于您想要的部分,我可以想到的一种方法是,确保此备份视图仅限于一个部分,即每当滚动表视图时,将备份视图的框架调整为该部分所覆盖的区域

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGRect sectionFrame = [self.tableView rectForSection:sectionWithBackground];
    self.sectionBackgroundView.frame = sectionFrame;
}

您还需要在开始时执行此操作(可能在ViewWillDisplay:)以确保视图正确启动

要在UITableView中的节后面添加背景图像以使其滚动,请在ViewDid中写入

let frame = tableView.rect(forSection: 0)
let view = UIView(frame: frame)
let imgView = UIImageView(frame: view.bounds)

// Assign image here ...

view.addSubview(imgView)

tableView.addSubview(view)
tableView.sendSubviewToBack(view)

注意:保持表格视图单元格的背景色清晰,以便背景视图可见 在表视图中更新数据后编写以下代码:

        let frame = tableView.rect(forSection: 0)
        let backgroundView = UIView(frame: frame)
        let imageView = UIImageView(frame: view.bounds)
        imageView.image = your image
        backgroundView.addSubview(imageView)
        tableView.addSubview(backgroundView)
        tableView.sendSubviewToBack(backgroundView)
        tableView.backgroundColor = .clear
之后,您需要将单元格置于
willDisplaycell
方法的前面,如下所示:

func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
        tableView.bringSubviewToFront(cell)
}

您想要做的事情似乎可以通过图层或使用子视图来实现。你能发布一个你要找的东西的模型吗?我会尽快上传我需要的图片!通常,每个单元格都有一个背景,可以是颜色,也可以是图像。但是,我想要一个单一的背景(在本例中是一个图像)放在我表格的一个部分的所有单元格后面。我明白。UITableView上有一个backgroundView属性,还有一个用于节标题的视图。不确定这些是否会有帮助。遗憾的是,桌子的背景是静态的,并且位于桌子后面。而标题仅位于特定部分的单元格上方。我需要一个背景去我的表后面的一个部分,并与它一起滚动。相当不错的解决方案,但它不是下面的部分,而在iOS 9滚动。。。