Reputation: 77
I'm, developing an iOS app that have a tableView and I want to insert a background image to this tableView.
I have added the following code to [viewDidLoad]
:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];
This code shows the image correctly, but when I scroll the tableView the image scrolls together, I want the image to be still and only the cells do the scrolling.
How can it be done?
Thanks
Upvotes: 0
Views: 581
Reputation: 101
Background Image Set in Objective C and Swift
Objective C
UIImage *img = [UIImage imageNamed:@"xyz.png"];
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:img];
Swift
self.tableView.backgroundView = UIImageView(image: UIImage(named: "xyz.png"))
Upvotes: 0
Reputation: 14857
Instead of using backgroundColor,you could use backgroundView.
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:@"bg.png"]];
Upvotes: 3