[英]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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.