0

I need to set an image as background for a TableView I got by adding a navigation controller to my scene. I tried using a UIImage but can't find where to put it in the hierarchy

since on StackOverflow you told that using a UIImage is wrong. I tried:

self.tableView.backgroundColor = UIColor(patternImage: UIImage(named: "back.image_")!)

but I have 3 problems

  • I want the background to be fixed, no scrolling.
  • the background is not a fixed image, I mean, image is not related to screen size
  • navigation bar hides the upper section of the image (that's why I wanted to use UIImage) is there a way to transform navigation bar clear but keep buttons visible?

So, I come back trying to use UIImageView. This is one of my tableView on Document Outline:

enter image description here

If I drag a UIImage this is the only place where i can put it:

enter image description here

With this weird result:

enter image description here

Thanks in advance

biggreentree
  • 1,633
  • 3
  • 20
  • 35
  • 1 & 2 - create an image behind the table and make the table background transparent. Transparent table and cells are a bit tricky but possible. 3. make navigation bar translucent. – Sulthan Sep 07 '15 at 14:55
  • I made clear cell's UI elements in the Utilities, my concern are on the background. in the utilities I set Translucent on the navigation bar, but I'd like it to be transparent – biggreentree Sep 07 '15 at 14:59

2 Answers2

0

To achieve the effect you want, I would create a UIImageView behind the table and make the table's background color UIColor.clearColor(). Or you can add it to the table's view hierarchy behind the cells and use auto-layout constraints to keep its position fixed.

There are lots of existing questions on Stack Overflow about transparent navigation bars. Perhaps start with this approach.

Community
  • 1
  • 1
Aaron Brager
  • 65,323
  • 19
  • 161
  • 287
  • Problem is, I don't know how to add the `UIImageView`, I added images in order to explain it better. Where should I put the `UIImage` in the hierarchy? – biggreentree Sep 26 '15 at 13:19
0

For a fixed image that doesn't scroll with the table, you have to use the superview's view. This code should work:

override func viewDidAppear(animated: Bool) {

    let sasha = UIImage(named: "sasha")!

    let sashaView = UIImageView(image: sasha)

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

Put this in the UITableViewController. Fixed image when scrolling.

kakubei
  • 5,321
  • 4
  • 44
  • 66