Reputation: 149
anyone know how to put a background image on Static UITableView? I have a dynamic prototypes UITableView and a Static UITableView.(Both tableView show many rows) And I want to use the same background image on both tableview. But I not sure how to add a background image on Static Cells UITableView. Any idea?
Upvotes: 1
Views: 874
Reputation: 313
Hope this helps.
You can add this code to viewdidload
let TempImageView = UIImageView(image: UIImage(named: "your_image"))
TempImageView.frame = self.TableView.frame
self.TableView.backgroundView = TempImageView
You will need to create tableview class and you will have to add the methods as below -
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return super.tableView .numberOfRows(inSection: section)
}
Also make sure cell background is set to clear color
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAt: indexPath)
cell.backgroundColor = UIColor.clear
return cell
}
Upvotes: 1