Author Topic: How to add a background image to a table view  (Read 6667 times)


  • Administrator
  • *****
  • Posts: 719
    • View Profile
How to add a background image to a table view
« on: September 21, 2015, 10:53:58 AM »
To add a background image to a table view, you create an image view and add it to the table view's backGroundView property.

For example:

Code: [Select]
let imageView = UIImageView(image: UIImage(named: "StarrySky"))
imageView.frame = self.tableView.frame
self.tableView.backgroundView = imageView

All the best!
Kevin McNeish
Author of Learn to Code in Swift:
Check out our Robot Tic-Tac-Toe app:
« Last Edit: November 11, 2015, 12:16:55 PM by kjmcneish »


  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: How to add a background image to a table view
« Reply #1 on: October 08, 2015, 05:31:53 PM »
How about an image above, or at the top of, a tableview that does not scroll up with the tableview.
An image view can be placed above a tableview but it scrolls up and out of sight.

The Apple documentation says how to use a header for sections of a tableview, and it says that a header can be used at the top of a tableview.
How do you put an image in the main header at the top that will not scroll up?

I want the image to stay at the top of the screen when the table is scrolled up.

I have found a way to do it using Objective-C but I want to use Swift.

« Last Edit: October 08, 2015, 05:34:17 PM by DennyS »