ios - 列表部分标题的 SwiftUI 2 清除背景
问题描述
SwiftUI 2 破坏了我的应用程序的一部分,该部分依赖于列表部分标题的清晰背景。以前我依靠这一行来使列表部分清晰。有谁知道如何在 SwiftUI 2 中实现这一点?
UITableViewHeaderFooterView.appearance().tintColor = .clear
这是一个适用于 SwiftUI 1 的示例:
struct ContentView: View {
var body: some View {
List {
Section(header:
Text("List Header")
) {
Text("Hi")
}
.listRowBackground(Color.clear)
}
.onAppear {
UITableViewCell.appearance().backgroundColor = UIColor.clear
UITableViewHeaderFooterView.appearance().tintColor = .clear
}
}
}
期望:List Header
应该是透明的而不是灰色的。
解决方案
以下代码将为您提供一个与系统背景颜色相同的空标题,如果您想向其中添加文本,您可以替换Rectangle
甚至Text("Your header")
使用Stack
View
List {
Section(header:
Rectangle()
.foregroundColor(.clear)
.listRowInsets(EdgeInsets())
.background(Color(.systemBackground))){
//content of the list
Text("Item x")
//...
}
}
推荐阅读
- angular - Angular Material Scroll 加载的项目比预期的要多
- r - 如何获得最后一个非零元素的位置
- linux - ls 命令中的额外转义字符使生活变得艰难
- regex - Python 正则表达式这个特定的字符串格式
- sql - NOT EXISTS 与 SELECT NULL 一起存在
- java - 带有 JWT 的 Keycloak SSO 这可能吗?
- tensorflow - 如何在 Keras 进行切片分配(使用 TensorFlow 作为后端)
- python - Discord.py def check_queue 发送消息
- android - 在现有项目 React-Native 中添加现有的原生项目 Android
- excel - 自动执行 xlsx 格式时触发的此工作簿事件时,焦点命令不起作用?