I have a ScrollView
displaying a list of items in a VStack
instead of using a List
. I'd like to replicate the behaviour of a .large
navigation bar title where the background color uses the .systemGroupedBackground
This is the behaviour of a List
that I'd like to have. The background of the Summary
is transparent.
This is the behaviour I get when using a ScrollView
+ VStack
. Note the white background of the large navigation bar.
The code to reproduce both is
import SwiftUI
struct MyContentView: View {
var body: some View {
NavigationView {
ScrollView {
VStack(spacing: 8) {
Text("One")
.roundedContainer()
Text("Two")
.roundedContainer()
}
.padding()
}
.background(Color(.systemGroupedBackground))
.navigationBarTitle("Summary", displayMode: .large)
}
}
}
struct MyListContentView: View {
var body: some View {
NavigationView {
List{
Text("One")
.padding()
Text("Two")
.padding()
}
.listStyle(InsetGroupedListStyle())
.navigationBarTitle("Summary", displayMode: .large)
}
}
}
extension View {
func roundedContainer() -> some View {
self
.frame(maxWidth: .infinity)
.padding(.vertical)
.background(Color.white)
.cornerRadius(10)
}
}
struct MyContentView_Previews: PreviewProvider {
static var previews: some View {
Group {
MyContentView()
MyListContentView()
}
}
}