ios - 如何使 SwiftUI 列表行背景颜色扩展整个宽度,包括安全区域之外
问题描述
在 SwiftUIList
中,如何使列表行背景(通过设置.listRowBackground()
)扩展视图的整个宽度,即使在安全区域下也是如此?例如,在宽屏 iPhone(例如 iPhone 12 Pro Max)上横向运行时。目前,在安全区域开始之前,该单元格在单元格的最左侧显示为白色。
示例代码:
struct ContentView: View {
var body: some View {
List {
Text("Test")
.listRowBackground(Color(.systemGray3))
}.listStyle(GroupedListStyle())
}
}
这会产生如下所示的 UI。我希望单元格的灰色背景可以扩展设备的整个宽度。
我已经尝试添加.edgesIgnoringSafeArea(.all)
到,Text
但它没有任何区别。
解决方案
答案是放在.edgesIgnoringSafeArea([.leading, .trailing])
背景Color
本身,而不是列表项。
struct ContentView: View {
var body: some View {
List {
Text("Test").listRowBackground(
Color(.systemGray3).edgesIgnoringSafeArea([.leading, .trailing])
)
}.listStyle(GroupedListStyle())
}
}
推荐阅读
- java - 正则表达式匹配某个模式和介于两者之间的某个数量的值
- reactjs - 无法在 useEffect 挂钩内设置状态
- android - 如何在颤动中将 Firebase 字段显示到列表视图中
- javascript - React/Forms:用户提交数据时如何通过useEffect等待更新数据,提交触发useEffect(需要时间)
- powershell - Windows powershell:更改默认工作目录
- google-authentication - Googleapis 服务帐户身份验证 Gaxios 错误
- mongodb-atlas - MongoDb领域同步忽略模式?
- google-apps-script - google.script.run.withSuccessHandler 返回未定义。我该如何解决?
- openlayers - 如何从修改交互的 OpenLayer LineString 中删除一个点(以前能够单击要删除的点)
- c# - 唯一列表,但保留空行