简体   繁体   中英

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

I am trying to make the list transparent so just the number of steps and the date they were taken appear on the background. Is there a way to make the grey background transparent and also do the same to the white in the cells of the list?

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()
}

What you need is to set your VStack's list row background to clear:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM