如何在横向的安全区域中设置 SwiftUI 列表标题的背景颜色?

问题描述

我正在尝试为横向列表标题设置安全区域的背景,但我似乎无法更改认的深灰色。我可以为行更改它,但不能为标题更改。我不想使用 GroupedListStyle。只想要一个普通列表,但要更改安全区域背景:

List {
    Section(header:
                HStack {
                    SearchBar()
                }
                .padding(.horizontal)
                .background(Color.white)
                .listRowInsets(EdgeInsets(top: 0,leading: 0,bottom: 0,trailing: 0))

    ) {
        ...
    }
}

enter image description here

我曾尝试使用 .edgesIgnoringSafeArea 设置背景,也尝试使用 ZStack 方法,但深灰色来自实际标题,无论如何我无法在横向中覆盖它。

解决方法

明确应用列表样式以修复所有模式(使用 Xcode 13 / iOS 15 测试)

List {
   // header here
   // content here
}
.listStyle(.plain)     // << here !!