kevinabraham
kevinabraham

Reputation: 1427

How to add image to table view controller

Im trying to add an image as a background behind table view controller with multiple cells,already I'm using an imageView but having an issue where the background doesn't go behind the text but above or below the cells.

enter image description here

My file structure looks like: enter image description here

Upvotes: 1

Views: 1395

Answers (3)

Tihomir Budic
Tihomir Budic

Reputation: 309

You need change the property of the background color for Tableview : clear background

Upvotes: 0

Sheereen S
Sheereen S

Reputation: 1236

To set overall background image to a UITableView use below code

var backGroundImage: UIImageView = UIImageView(image: UIImage(named:  "backGroundImage.png"))
self.tableView.backgroundView = backGroundImage

Upvotes: 2

Jayesh Miruliya
Jayesh Miruliya

Reputation: 3317

override func viewDidLoad()
{
     let img:UIImageView=UIImageView(frame: PostTable.frame)
     img.image=UIImage(named: "hi.png")
     PostTable.backgroundView=img
}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cell:UITableViewCell! = tableView.dequeueReusableCellWithIdentifier("cell")

        let selectView=UIView()
        selectView.backgroundColor=UIColor.clearColor()
        cell.selectedBackgroundView=selectView
        cell.backgroundColor=UIColor.clearColor()
        cell.contentView.backgroundColor=UIColor.clearColor()

        return cell!
    }

Upvotes: 0

Related Questions