UITableView Section Background?

To add background image behind section in UITableView so that it scrolls, write in viewDidAppear

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)

NOTE: Keep the background color of table view cells clear so that background view is visible


Swift 5
write the following code after update data in the table 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

After that , you will need to bring the cells to the front in willDisplaycell method as the following :

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

You can place a view behind your table view, set the table view's background colour to [UIColor clearColor] and you will see the view behind

[self.view addSubview:self.sectionBackgroundView];
[self.view addSubview:self.tableView];
self.tableView.backgroundColor = [UIColor clearColor];

the drawback to this is that this will not be only limited to the section you want, one way I can think of to make sure this backing view is limited to one section only is to adjust the frame of the backing view to the area covered by the section whenever the table view is scrolled

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

you will need to do this at the start (probably in viewWillAppear:) as well to make sure the view starts off correctly.