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

kjmcneish

  • 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: https://itunes.apple.com/us/book/learn-to-code-in-swift/id942956811?mt=11
Check out our Robot Tic-Tac-Toe app: https://itunes.apple.com/us/app/robot-tic-tac-toe/id990638517?mt=8
« Last Edit: November 11, 2015, 12:16:55 PM by kjmcneish »

DennyS

  • 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.

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