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

swift-iOS14中表格部分标题中的白色背景

(swift - White background in table section header in iOS14)

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

使用xcode12构建到iOS14后出现此问题

我有一个带有透明背景的节标题,在iOS14上,它变成了白色,_UISystemBackgroundView并在层次结构中添加了新的标题

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

iOS 14带有两个新的单元配置:

  1. 内容配置。 UIContentConfiguration

顾名思义,内容配置可以帮助你操纵单元格的内容,例如图像,文本,辅助文本,布局指标和行为。

  1. 后台配置 UIBackgroundConfiguration

可以帮助操纵背景颜色,视觉效果,笔触,插图和拐角半径。即使我们未指定默认设置,所有单元也会继承默认的后台配置。

解决方案

要摆脱默认的iOS14白色背景,你需要按以下方式更改UITableViewCellor UITableViewHeaderFooterViewbackgroundConfiguration

    // 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
    }

阅读这篇文章以了解更多