Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Fixed Background image in a TableView ?

Hey guys !

My first question as a Swift nOOb !

I'm trying to set up a fixed image as a background for my Table View. So far, the best option has been to include this in my ViewDidLoad :

    let uluru = UIImage(named: "Uluru")
    self.view.backgroundColor = UIColor(patternImage: uluru!)

Not so great, right?

Especially because when you're scrolling, the image is tiled. Meaning, it's repeating itself. Does anyone has a solution via the IB or directly into the code to make it fixed ? Something like <body style="background-attachment:fixed;"> in CSS ?

Thank you all!

I also try the superview way :

override func viewDidAppear(animated: Bool) {

    let uluru = UIImage(named: "Uluru")

    let uluruView = UIImageView(image: uluru)

    self.view.superview!.insertSubview(uluruView, belowSubview:self.view)
}

Nothing appears!

3 Answers

Hey Antoine Streiff,

You can set the backgroundView property of your tableView to a UIImageView.

tableView.backgroundView = UIImageView(image: UIImage(named: "yourImageName"))

Hope this is what you were looking for. Good Luck

Thanks! But where do you put that line? In a func?

You put it in your viewDidAppear or viewDidLoad

Thanks!