SwiftUI如何使列表和分区透明
我正在尝试制作一个类似以下内容的列表: 但是,无论我怎么做,我都无法弄清楚如何使列表和部分都具有SwiftUI如何使列表和分区透明,swift,swiftui,Swift,Swiftui,我正在尝试制作一个类似以下内容的列表: 但是,无论我怎么做,我都无法弄清楚如何使列表和部分都具有.clear背景,目前看起来是这样的: 我尝试将.background(Color.clear)添加到列表和部分,但没有成功。 当我使用透明以外的任何其他颜色时,它的变化都很好。但似乎在背景色的“背后”有某种东西使它下面仍然显示出白色和灰色 如何更改此列表以使其完全清晰 以下是我当前失败的尝试: var body: some View { NavigationView {
.clear
背景,目前看起来是这样的:
我尝试将.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)
}
但似乎背景色的“背后”有什么东西
这使得它仍然显示白色和灰色的下面
请尝试删除UITableView
和UITableViewCell
背景色:
UITableView.appearance().backgroundColor = .clear
UITableViewCell.appearance().backgroundColor = .clear
在init内部添加外观样式
init() {
UITableViewCell.appearance().backgroundColor = .clear
UITableView.appearance().backgroundColor = .clear
UITableView.appearance().sectionIndexBackgroundColor = .clear
}
您还需要更改列表样式
,以使SectionBackground透明
.listStyle(GroupedListStyle())
编辑:在您的案例中使用InsetGroupedList更好。多亏了pawello22222
.listStyle(InsetGroupedListStyle())
实际上它可以是
.listStyle(InsetGroupedListStyle())
-它应该更符合OP的要求(至少我这么认为)。@pawello2222是的,这样更好。谢谢我会编辑它,非常感谢你!这是我的第一个Swift应用程序,不知道如何覆盖默认值,所以这非常有用!