Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableViewController - image background

i have UITableViewController, and I'm trying to set a image background. the issue is the background image does not fit the whole screen, in other words, the image background does not stretch with the table cells. this my code

    let imgView =  UIImageView(frame: self.tableView.frame)
    let img = UIImage(named: "b2")
    imgView.image = img
    imgView.frame = CGRectMake(0, 0, self.tableView.frame.width, self.tableView.frame.height)
    imgView.contentMode = UIViewContentMode.ScaleAspectFill
    self.tableView.addSubview(imgView)
    self.tableView.sendSubviewToBack(imgView)

enter image description here

like image 837
Makaveli Avatar asked Feb 05 '16 04:02

Makaveli


People also ask

How to Set background image for UITableView in ios?

backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"TableViewBackground. png"]]; Thank you in advance!


1 Answers

Try with this code:

 tableView.backgroundView = UIImageView(image: UIImage(named: "640x1136.png"))

enter image description here

Add this code in ViewDidLoad

like image 192
Amit Thakur Avatar answered Oct 11 '22 09:10

Amit Thakur