Quantcast
Channel: Active questions tagged listview - Stack Overflow
Viewing all articles
Browse latest Browse all 611

How do a create a reusable simple custom list style with my own color and spacing

$
0
0

I want all the lists in my application to look exactly the same and don't want to respecify all these settings over and over. I get the following error: Cannot find type 'Configuration' in scope. I currently have something like this:

struct CustomListStyle: ListStyle {    func makeBody(configuration: Configuration) -> some View {        ScrollView {            VStack(spacing: 10) {                ForEach(configuration.data, id: \.self) { item in                    Text(item as? String ?? "")                        .foregroundColor(.blue)                        .padding(10)                         .background(Color.gray)                         .cornerRadius(10)                }            }            .padding()         }    }}struct ContentView: View {    var body: some View {        List(0..<10, id: \.self) { index in            Text("Item \(index)")        }        .listStyle(CustomListStyle())    }}

Edit - 1 - Here is one for reference

List( selection: $dm.someVar ) {    Section( ) {        LazyVGrid(columns: [            GridItem(.flexible(minimum: 120)),        ], alignment: .leading, spacing: 10) {            ForEach(0..<20, id: \.self) { index in                Text("Column1 abcdef: \(index)")            }        }    }}

Viewing all articles
Browse latest Browse all 611

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>