My iPad app makes use of a 3-column layout using SwiftUI's NavigationView
, 2 List
s, and then the content view. The first List
acts as the primary navigation screen, and the (relevant) code looks roughly like this:
var body: some View {
List {
...snip...
}
}
.listStyle(SidebarListStyle())
.accentColor(.white)
.introspectTableView { tableView in
tableView.backgroundColor = UIColor(Color.blue)
}
.navigationBarItems(trailing: Button(action: { self.isCreating = true }) {
Label("", systemImage: "plus")
.foregroundColor(.white)
})
}
As shown in the code, I was using the awesome Introspect library to get access to the underlying UITableView
so I could set the background color. In iOS 14 this renders properly, as a List with a blue background. (See screenshot below)
However, in iOS 15 the background color is not applied. (See screenshot)
I have tried a couple different methods for setting the background color in iOS 15. The Introspect code doesn't seem to get called at all, so I tried:
List {
}
.background(Color.blue)
That did absolutely nothing. I also tried setting UITableView.appearance().backgroundColor
to the appropriate value, however that will change the background of all UITableView
s globally. That is not the behavior I want. I only want this one List
to have that background color.
Is this a bug in iOS 15 or SwiftUI? Is there a new way for setting the background color on a List? Does this have something to do with the fact that my listStyle
is set to SidebarListStyle
?
Any help or guidance would be greatly appreciated!!