I have a simple table view, I can change the colors of cells, but when trying to change the color of Table View (Background part) it is not working... I tried it via Storyboard.
I'm a little late to the game! But, none of the above answers worked for me, so just going to share, what I found worked, in case anyone else is jumping on this thread.
NOTE: I also have my own custom cell class. Not sure if that will affect your code!
@IBDesignable class YourViewController: UITableViewController {
//IBInspectable and IBDesignable makes the properties accessible in storyboard
@IBInspectable var tableViewBackground: UIColor?
@IBInspectable var cellViewBackground: UIColor?
//in case you want to customize the text color, as well!
@IBInspectable var customTextColor: UIColor?
override func viewDidLoad() {
//your code
self.tableView.backgroundColor = tableViewBackground
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell()
cell.textLabel?.textColor = customTextColor
cell.backgroundColor = cellViewBackground
return cell
}
//the rest of your code
}
Finding your inspectables:
1). In the Storyboard menu for the viewController of your tableView, click on yourViewController. The first dropdown inside the viewController. (The first dropdown will contain your tableView and cellView. It can also contain other goodies depending on your particular project).
2). In the attributes inspector, you'll see a heading with the name of your viewController and the @IBInspectable properties we defined above!!
3). You can then change them however you want there.
Hope this helps!