16

When using ScrollView the views inside it are spread across the whole screen width by default, but when using List, there is a padding on the sides. Is there a way to get rid of this padding?

2 Answers 2

35

To achieve this you need to use ForEach inside List combined with .listRowInsets as in example below

demo

struct Demo: View {
    var colors: [Color] = [.red, .blue, .yellow]
    var body: some View {
        List {
            ForEach(colors, id: \.self) { color in
                color
            }.listRowInsets(EdgeInsets())
        }
        // Update: Different iOS versions have different 
        // default List styles, so set explicit one if needed
        .listStyle(PlainListStyle())
    }
}
Sign up to request clarification or add additional context in comments.

Comments

6

For iOS 15.0+, you may try listStyle modifier and set it as plain.

var body: some View {
        List {
            // some rows
        }
        .listStyle(.plain)
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.