I\'m trying to change the background color of UITableViewHeaderFooterView. Although the view is appearing, the background color remains the default color. I\'m getting a log
iOS 12, Swift 5. If you are willing (or trying!) to use an appearance proxy, the following solution works:
final class MySectionHeaderView: UITableViewHeaderFooterView {
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
}
@objc dynamic var forceBackgroundColor: UIColor? {
get { return self.contentView.backgroundColor }
set(color) {
self.contentView.backgroundColor = color
// if your color is not opaque, adjust backgroundView as well
self.backgroundView?.backgroundColor = .clear
}
}
}
MySectionHeaderView.appearance().forceBackgroundColor = .red
or
MySectionHeaderView.appearance(whenContainedInInstancesOf: [MyOtherClass.self]).forceBackgroundColor = .red