Warm tip: This article is reproduced from serverfault.com, please click

White background in table section header in iOS14

发布于 2020-10-14 14:09:55

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.

Questioner
Husam
Viewed
0
Husam 2020-10-14 22:09:55

iOS 14 comes with new two cell configurations:

  1. Content 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.

  1. Background configurations 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.

The Solution

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