swift - 如何在 Swift 中使列表完全透明?
问题描述
我是 SwiftUI 初学者。我在 SwiftUI 应用程序中根据需要创建列表时遇到问题!
这是我的代码:
struct Search: View {
@ObservedObject var webservice = Webservice()
@State var depart = "Gent-Sint-Pieters"
@State var destination = "Mechelen"
var body: some View {
VStack (spacing: 20){
Rechercher(depart: $depart , destination: $destination)
HStack {
List(webservice.rides, id:\.id) { item in
Text("")
}
//.colorMultiply(Color(hue: 0.547, saturation: 0.071, brightness: 1.0))
Spacer()
}
RechercheButton()
}
}
}
我想要的是删除列表的白色背景。可能吗 ?
你能告诉我我需要在这段代码中添加什么以获得这样的结果(每个灰色分隔线之间有一个内容,并且列表没有背景颜色)吗?
谢谢你 !!
解决方案
在视图的 init 方法中设置清除颜色
init() {
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear
}
因此,您的答案将如下所示
struct Search: View {
@ObservedObject var webservice = Webservice()
@State var depart = "Gent-Sint-Pieters"
@State var destination = "Mechelen"
init() {
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear
}
var body: some View {
VStack (spacing: 20){
Rechercher(depart: $depart , destination: $destination)
HStack {
List(webservice.rides, id:\.id) { item in
Text("")
}
//.colorMultiply(Color(hue: 0.547, saturation: 0.071, brightness: 1.0))
Spacer()
}
RechercheButton()
}
}
}
推荐阅读
- python - Heroku 上的 Scrapy 爬虫返回 503 服务不可用
- c - -2^31 作为最小整数,为什么?
- c# - 导出 Excel 报表服务器时,现有连接被远程主机强行关闭
- python - 从 PyTorch 中的网络输出计算梯度会出错
- svg - 为什么渲染一组 svg 与一个 svg 不同?
- python - 如何在 python 3.6 中使用分布式包?
- java - 在 Android 5 中支持 JAVA-8 Jar - React Native
- javascript - 设置超时后InnerText闪烁
- in-app-purchase - 如何在 App Purchase 中获取 Volume App Store
- angular - 材质对话框中的黑色外部区域