Starting with iOS 16, you can customize the color of the scrollable area of a list view. Simply set the background color using the background modifier and attach the scrollContentBackground modifier to the List view. By setting the parameter to .hidden, you can easily change the scroll view’s background to another color as in this code example:
List {
ForEach(restaurants.indices, id: \.self) { index in
if(0...1).contains(index) {
FullImageRow(restaurant: restaurants[index])
}else{
BasicImageRow(restaurant: restaurants[index])
}
}
.listRowSeparator(.hidden)
}
.background(.blue)
.scrollContentBackground(.hidden)
The result in XCode would be the following:
![](https://swiftprogramming.com/wp-content/uploads/2024/12/backgroundlist1.png)
How to add an image as a background
We can also set an image as a background, using the following Swift code with the SwiftUI framework:
.background{
Image("homei")
.resizable()
.scaledToFill()
.clipped()
.ignoresSafeArea()
}
.scrollContentBackground(.hidden)