Reputation: 126
I'm trying to get the background of my UITableViewCell's AccessoryView to be the same color as the rest of my cell, but I cannot get it work out. No matter what the AccessoryView background is always gray
My UITableView uses STATIC cells, so no data is loaded.
Here's my code:
// Table setup
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.accessoryType = .checkmark
cell?.contentView.backgroundColor = #colorLiteral(red: 0.2250251152, green: 1, blue: 0.1816247099, alpha: 0.5082940925)
cell?.backgroundColor = #colorLiteral(red: 0.2250251152, green: 1, blue: 0.1816247099, alpha: 0.5082940925)
(superView as! ProjectTestSelectViewController).updateProjectHandlerTests(cell!, didSelect: true)
}
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
let cell = tableView.cellForRow(at: indexPath)
cell?.contentView.backgroundColor = UIColor(white: 1, alpha: 0.2)
cell?.backgroundColor = UIColor(white: 1, alpha: 0.2)
cell?.accessoryType = .none
(superView as! ProjectTestSelectViewController).updateProjectHandlerTests(cell!, didSelect: false)
}
override func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {
cell.contentView.backgroundColor = UIColor(white: 1, alpha: 0.2)
cell.backgroundColor = UIColor(white: 1, alpha: 0.2)
}
override func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) {
view.tintColor = UIColor(white: 1, alpha: 0.8)
}
Here's a screenshot
I've tried using the code below, but it does not effect the background color.
cell?.accessoryView?.backgroundColor = UIColor.clear
Upvotes: 3
Views: 1140