skip to Main Content

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.

4

Answers


  1. Chosen as BEST ANSWER

    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


  2. Objective-C version of @Husam solution:

    if (@available(iOS 14.0, *)) {
        UIBackgroundConfiguration *bgConfig = [UIBackgroundConfiguration listPlainCellConfiguration];
        bgConfig.backgroundColor = UIColor.clearColor;
        [UITableViewHeaderFooterView appearance].backgroundConfiguration = bgConfig;
    }
    
    Login or Signup to reply.
  3. 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];
    }
    
    Login or Signup to reply.
  4. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search