如何使 SwiftUI 列表的背景透明?

How do I make the background of a SwiftUI list transparent?

我正在尝试使列表透明化,以便在背景上只显示步数和步数。有没有办法让灰色背景透明,同时对列表单元格中的白色也做同样的事情?

CustomNavigationLink(title: "Steps (Last 7 Days)") {
    List(listSteps, id: \.id) { stepList in
        VStack(alignment: .leading) {
            Text("\(stepList.count)")
                .font(.custom(customFont, size: 40))
                .fontWeight(.semibold)
            Text(stepList.date, style: .date)
                .opacity(0.5)
                .font(.custom(customFont, size: 20))
                .foregroundColor(.cyan)
                .padding(1)
        }
    }
    .background(Image("GreenBG"))
    .navigationTitle("Steps (last 7 days)")
    .padding()
}

您需要将您的 VStack 的列表行背景设置为清除:

VStack(alignment: .leading) {
    Text("\(stepList.count)")
        .font(.custom(customFont, size: 40))
        .fontWeight(.semibold)            
    Text(stepList.date, style: .date)
        .opacity(0.5)
        .font(.custom(customFont, size: 20))
        .foregroundColor(.cyan)
        .padding(1)
}
.listRowBackground(Color.clear)