Swift UI Overlay a list to a background color

夙愿已清 提交于 2020-03-23 07:50:40

问题


I just want to set a Color as background color to my list. Can't find anything that work,

It looks like is not possible, I don't want to change every single color of my row.

Any tips how to do it? Looks like SwiftUI and List don't allow the background color, it allow only color per single raw.

struct ContentView: View {
    var body: some View {
        ZStack {
            RadialGradient(gradient: Gradient(colors: [.orange, .red]), center: .center, startRadius: 100, endRadius: 470).edgesIgnoringSafeArea(.all)
                .overlay(
                    List(0 ..< 5) { item in
                        Text("Test")
                    }
            )
        }
    }
}

回答1:


You can add

init() {
    UITableView.appearance().backgroundColor = .clear
    UITableViewCell.appearance().backgroundColor = .clear 
}

to your struct and then set background for your list.



来源:https://stackoverflow.com/questions/60133411/swift-ui-overlay-a-list-to-a-background-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!