gpt4 book ai didi

SwiftUI如何使List和Section透明

转载 作者:行者123 更新时间:2023-12-04 00:53:04 24 4
gpt4 key购买 nike

我正在尝试制作一个看起来像这样的列表:

enter image description here

但是无论我尝试什么,我都无法弄清楚如何使列表和部分都具有 .clear 背景,目前它看起来像这样:

enter image description here

我尝试将 .background(Color.clear) 添加到列表和部分,但没有成功。当我使用透明以外的任何其他颜色时,它确实会很好地改变。但似乎背景颜色“背后”有某种东西使它仍然在下面显示白色和灰色......

如何更改此列表以使其完全清晰?

这是我目前失败的尝试:

var body: some View {
NavigationView {
List {
ForEach(uniqueEntries, id: \.self) { category in
Section(header: HStack {
Text(category)
.font(.headline)
.foregroundColor(.white)
.padding()
Spacer()
}
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.background(Color.clear)
) {
ForEach(self.entriesCollatedByCategory[category]!) { entry in
ExpenseRow(entry: entry)
.listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
.listRowBackground(Color.clear)


}
}
}
}
.padding()
.background(Image("tempGradientBackground")
.resizable()
.aspectRatio(contentMode: .fill))
.navigationBarTitle(Text("Budget"))
}.background(Color.clear)
}

最佳答案

在init里面添加外观样式

init() {
UITableViewCell.appearance().backgroundColor = .clear
UITableView.appearance().backgroundColor = .clear
UITableView.appearance().sectionIndexBackgroundColor = .clear
}

您还需要更改 ListStyle 以使 SectionBackground 透明

.listStyle(GroupedListStyle())

编辑:在您的案例中使用 InsetGroupedList 会更好。感谢 pawello22222

.listStyle(InsetGroupedListStyle())

关于SwiftUI如何使List和Section透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64884505/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com