Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
SwiftUI Transparent List Wrapper - Works in iOS 14
/// Wraps its content in a HostingViewController that has the backgroundColor of UITableView appearance
/// within it set to .clear, thus working around the issue where SwiftUI Lists always have white backgrounds,
/// without inadvertently affecting the appearance of all UITableViews in the app.
/// Setting the listRowBackground explicitly is still required, setting that to clear won't work.
struct ListAppearanceContainer<Content>: View, UIViewControllerRepresentable where Content: View {
let content: Content
class AppearanceContainerViewController<Content>: UIHostingController<Content> where Content: View {}
init(_ content: () -> Content) {
self.content = content()
func makeUIViewController(context: Context) -> AppearanceContainerViewController<Content> {
let tableView = UITableView.appearance(whenContainedInInstancesOf: [AppearanceContainerViewController<Content>.self])
tableView.backgroundColor = .clear
let vc = AppearanceContainerViewController(rootView: content)
vc.view.backgroundColor = .clear
return vc
func updateUIViewController(_ uiViewController: AppearanceContainerViewController<Content>, context: Context) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment