【问题标题】:How can I set background color of SwiftUI List Header in safe area in Landscape?如何在横向安全区域设置 SwiftUI 列表标题的背景颜色?
【发布时间】:2021-09-30 06:11:08
【问题描述】:

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

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

    ) {
        ...
    }
}

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

【问题讨论】:

    标签: ios xcode swiftui swiftui-list


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-12
      • 2018-04-25
      • 2019-11-29
      • 1970-01-01
      相关资源
      最近更新 更多