This issue appeared after building to iOS14 with xcode12.
I have a section header with transparent background, on iOS14 it becomes white with new _UISystemBackgroundView
added to the hierarchy.
iOS 14 comes with new two cell configurations:
UIContentConfiguration
As the name suggests, content configurations can help you manipulate the content of the cell like image, text, secondary text, layout metrics and behaviors.
UIBackgroundConfiguration
can help with the manipulation of background color, visual effect, stroke, insets and corner radius. All cells will inherit a default background configuration even if we don’t specify one.
To get rid of the default iOS14 white background you need to change the UITableViewCell
or UITableViewHeaderFooterView
backgroundConfiguration as follows
// Add this code in your AppDelegate didFinishLauncingWithOptions
// or you can change configuration of certain subclass using self. backgroundConfiguration = ...
if #available(iOS 14.0, *) {
var bgConfig = UIBackgroundConfiguration.listPlainCell()
bgConfig.backgroundColor = UIColor.clear
UITableViewHeaderFooterView.appearance().backgroundConfiguration = bgConfig
//For cell use: UITableViewCell.appearance().backgroundConfiguration = bgConfig
}
Read this article for more
In your UITableViewHeaderFooterView / UITableViewCell custom class - override next method with implementation example:
Swift:
@available(iOS 14.0, *)
override func updateConfiguration(using state: UICellConfigurationState) {
backgroundConfiguration = UIBackgroundConfiguration.clear()
}
Objective-C:
- (void)updateConfigurationUsingState:(UICellConfigurationState *)state {
self.backgroundConfiguration = [UIBackgroundConfiguration clearConfiguration];
}
Objective-C version of @Husam solution:
if (@available(iOS 14.0, *)) {
UIBackgroundConfiguration *bgConfig = [UIBackgroundConfiguration listPlainCellConfiguration];
bgConfig.backgroundColor = UIColor.clearColor;
[UITableViewHeaderFooterView appearance].backgroundConfiguration = bgConfig;
}
Use iOS 14's configuration based APIs may disable the functions of those legacy APIs (e.g. cell.textLabel
, cell.detailTextLabel
).
To prevent this system behavior, you can set a backgroundView
(legacy API) to your header/footer/cell, and then set a custom backgroundColor
for that view.