Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Remove background from SwiftUI's List in iOS 16

This is probably an old issue. but I still couldn’t find a workable solution.

Like the image below. I want to have the blue background extended to the whole list view on top. However, SwiftUI automatically adds two white backgrounds(potential from UICollection View or somewhere). Does anyone knows how to remove those white backgrounds from the SwiftUI’s List?

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Minimal Code to reproduce the issue. Here the two backgrounds are black and blocks out the blue background.

struct ContentView: View {
    var body: some View {
        List {
            Text("Hello World")
            Text("Hello World")
            Text("Hello World")
        }
        .background(Color.blue)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

enter image description here

>Solution :

On iOS 16 you need to use .scrollContentBackground(.hidden) in addition to setting background color:

List {
    Text("Hello World")
    Text("Hello World")
    Text("Hello World")
}
.background(Color.blue)
.scrollContentBackground(.hidden)

Prior to iOS 16, there was a few workarounds, the most reliable one was with retrospect (example)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading