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
Antoine Streiff
4,649 PointsFixed 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!
3 Answers
Steven Deutsch
21,046 PointsHey 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
Antoine Streiff
4,649 PointsThanks! But where do you put that line? In a func?
Steven Deutsch
21,046 PointsYou put it in your viewDidAppear or viewDidLoad
Antoine Streiff
4,649 PointsThanks!
Antoine Streiff
4,649 PointsAntoine Streiff
4,649 PointsI also try the superview way :
Nothing appears!