0

How can I change the color of the UITableView for the entire application?

Currently I have this set in some of my controllers but it does not work for some parts of the tableview.

self.tableView.backgroundColor = UIColor(red:0.20, green:0.22, blue:0.29, alpha:1.0)
rmaddy
  • 314,917
  • 42
  • 532
  • 579

1 Answers1

0

UIAppearance does not support to change the background color of tableview in globally, you need to create the extension that inherits from UITableView, here is a link to an answer containing a list of all methods supported by UIAppearance.

for e.g

extension UITableView {

 func setBGforTable(){
let divideCount: CGFloat = 255.0
self.backgroundColor = UIColor(red:0.20/divideCount, green:0.22/divideCount, blue:0.29/divideCount, alpha:1.0)

}
}

and call the method in your VC as

 override func viewDidLoad() {
     super.viewDidLoad() 
    yourtableViewName.setBGforTable()
  }
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143