2

In SwiftUI it appears there are two options for modifying colors to a list.

  1. Set a list's row background color

    List {        
      ForEach(elements, id:\.self) { element in
      }.listRowBackground(Color.blue)
    }
    
  2. Set a list's color scheme to either 'light' or 'dark'

     List {        
       ForEach(elements, id:\.self) { element in
       }
     }.colorScheme(.light) // .dark
    

Setting other attributes like background, foreground color, etc... seems to have zero effect on the view color of interest.

At the moment I do have the List embedded in a Navigation View as such:

NavigationView {
  List {        
    ForEach(elements, id:\.self) { element in
    }
  }.colorScheme(.light) // .dark
}

But again, no color settings or view hierarchy setup seem to enable to ability to set the background view to clear/transparent so the color of the main view can be the driver. Rather it appears from experimentation that we are forced to choose either a white or black background. Is this a swift or Xcode bug or are there any solutions available?

enter image description here

lifewithelliott
  • 1,012
  • 2
  • 16
  • 35

1 Answers1

7

In order to set a List View Background Color one must set the scrollContentBackground attribute to hidden and the background attribute to a color

List {
  ForEach(elements, id:\.self) { element in 
  }.listRowBackground(Color.white)
}.scrollContentBackground(.hidden)
 .background(Color.blue)

enter image description here

lifewithelliott
  • 1,012
  • 2
  • 16
  • 35