With the new SwiftUI
update in iOS 16 List
no longer depends on UITableView
. So the following snippet we used to set the List
background color to .clear
is now useless:
UITableView.appearance().backgroundColor = .clear
I saw that someone used introspect
to solve the problem, but does anyone know of another maybe cleaner way to achieve the same behavior?
Also note that on macOS
, the following works fine (Tested using Xcode 14 beta
& macOS Ventura
):
extension NSTableView {
open override func viewDidMoveToWindow() {
super.viewDidMoveToWindow()
backgroundColor = NSColor.clear
enclosingScrollView!.drawsBackground = false
}
}
iOS 16 adds a new modifier, scrollContentBackground(Visibility), to customize the background visibility for scrollable views including List
.
You can hide the standard system background like so which will reveal the List's background if you provide one:
List {
Text("One")
Text("Two")
Text("Three")
}
.background(Image("MyImage"))
.scrollContentBackground(.hidden)