SwiftUI在列表元素上清除背景

SwiftUI在列表元素上清除背景,swiftui,swiftui-list,swiftui-navigationview,Swiftui,Swiftui List,Swiftui Navigationview,我有一个用ForEach生成卡片视图的列表。它们应该有一个清晰的背景,但其中一个总是有一个白色的背景,我不知道如何改变它。我尝试过在我能想到的任何视图上放置.background(Color.clear),也尝试过使用.listRowBackground(Color.clear),但是一个视图仍然有一个背景,尽管它与所有其他视图相同 下面是一张图片,展示我所说的内容: 下面是navigationView主体的代码,这些代码显示在: NavigationView{ Lis

我有一个用ForEach生成卡片视图的列表。它们应该有一个清晰的背景,但其中一个总是有一个白色的背景,我不知道如何改变它。我尝试过在我能想到的任何视图上放置
.background(Color.clear)
,也尝试过使用
.listRowBackground(Color.clear)
,但是一个视图仍然有一个背景,尽管它与所有其他视图相同

下面是一张图片,展示我所说的内容:

下面是navigationView主体的代码,这些代码显示在:

NavigationView{
            List{
                //loop through task cards
                ForEach(self.tasks, id: \.id) { task in
                    //show task card
                    task
                        .listRowBackground(Color.clear)
                        .background(Color.clear)
                }
                .listRowBackground(Color.clear)
                .listStyle(SidebarListStyle())
                .environment(\.defaultMinListRowHeight, 120).padding(0.0)
                
            //LIST end
            }
            .listStyle(SidebarListStyle())
            .environment(\.defaultMinListRowHeight, 120).padding(0.0)
            .background(Color.clear)
            
        //NAVIGATION VIEW end
        }.background(Color.clear)
        .stackOnlyNavigationView()
下面是出现在上述ForEach中的视图主体的代码(称为“任务”):


尝试使用
.clipShape
,但很难说没有代码的确切位置

GeometryReader{ geo in
    RoundedRectangle(cornerRadius: 10)
        .foregroundColor(Color.lightAccent)
        .background(Color.clear)
        .frame(height: self.height)
        .overlay(
            HStack{
                //blah blah blah probably not important to the issue
                //if it is let me know and I will edit

            //HSTACK
            }.frame(width: geo.size.width, height: self.height)
                .cornerRadius(10)
                .overlay(
                    RoundedRectangle(cornerRadius: 10)
                        .stroke((self.id == self.selectionManager.id) ? Color.blue : Color.mid, lineWidth: (self.id == self.selectionManager.id) ? 3 : 1))
                          .background(Color.clear)
                          .foregroundColor(Color.clear)
                //OVERLAY end
                )
               .clipShape(RoundedRectangle(cornerRadius: 10))     // << here !!
    }
    .clipShape(RoundedRectangle(cornerRadius: 10))     // << or here !!
GeometryReader{geo-in
圆角转角(拐角半径:10)
.foregroundColor(颜色。lightAccent)
.背景(颜色.清晰)
.框架(高度:自身高度)
.覆盖(
HStack{
//诸如此类的废话可能对这个问题并不重要
//如果它是让我知道,我会编辑
//HSTACK
}.框架(宽度:geo.size.width,高度:self.height)
.转弯半径(10)
.覆盖(
圆角转角(拐角半径:10)
.stroke((self.id==self.selectionManager.id)?Color.blue:Color.mid,线宽:(self.id==self.selectionManager.id)?3:1)
.背景(颜色.清晰)
.foregroundColor(颜色.透明)
//覆盖端
)

.clipShape(圆角矩形(拐角半径:10))/尝试使用
.clipShape
,但很难说没有代码的确切位置

GeometryReader{ geo in
    RoundedRectangle(cornerRadius: 10)
        .foregroundColor(Color.lightAccent)
        .background(Color.clear)
        .frame(height: self.height)
        .overlay(
            HStack{
                //blah blah blah probably not important to the issue
                //if it is let me know and I will edit

            //HSTACK
            }.frame(width: geo.size.width, height: self.height)
                .cornerRadius(10)
                .overlay(
                    RoundedRectangle(cornerRadius: 10)
                        .stroke((self.id == self.selectionManager.id) ? Color.blue : Color.mid, lineWidth: (self.id == self.selectionManager.id) ? 3 : 1))
                          .background(Color.clear)
                          .foregroundColor(Color.clear)
                //OVERLAY end
                )
               .clipShape(RoundedRectangle(cornerRadius: 10))     // << here !!
    }
    .clipShape(RoundedRectangle(cornerRadius: 10))     // << or here !!
GeometryReader{geo-in
圆角转角(拐角半径:10)
.foregroundColor(颜色。lightAccent)
.背景(颜色.清晰)
.框架(高度:自身高度)
.覆盖(
HStack{
//诸如此类的废话可能对这个问题并不重要
//如果它是让我知道,我会编辑
//HSTACK
}.框架(宽度:geo.size.width,高度:self.height)
.转弯半径(10)
.覆盖(
圆角转角(拐角半径:10)
.stroke((self.id==self.selectionManager.id)?Color.blue:Color.mid,线宽:(self.id==self.selectionManager.id)?3:1)
.背景(颜色.清晰)
.foregroundColor(颜色.透明)
//覆盖端
)

.clipShape(圆角半径:10))//对于List或NavigationView,.background都不起作用。它是布局中的一部分。调试时需要最小的可复制示例。您能详细说明一下吗?这很好。那么.listRowBackround呢?这不应该起作用吗?另外,您还想了解布局中的其他内容吗?.background也不起作用对于List或NavigationView,它是布局中的一部分。调试时需要最少的可复制示例。您能详细说明一下吗?这很好。关于.listRowBackround呢?这不管用吗?另外,您还想了解布局中的哪些内容?我尝试在这两个位置以及列表元素和没有任何帮助。此外,我注意到,如果我在列表中滚动一点,列表中的其他元素上就会出现以前没有的背景。我不好意思说,回顾一下我在错误视图中应用剪贴画的项目。这是正确的答案,谢谢。我试着将它添加到这两个项目中此外,我注意到,如果我在列表中滚动一点,列表中的其他元素上就会出现以前没有的背景。我不好意思说,回顾一下我在错误视图中应用剪贴画的项目。这是正确的答案,谢谢。