[ACCEPTED]-iOS 16 SwiftUI List Background-ios16
Accepted answer
iOS 16
Now they use UICollectionView
for backend, so an updated 2 workaround is to change corresponding background 1 colors:
Main part:
extension UICollectionReusableView {
override open var backgroundColor: UIColor? {
get { .clear }
set { }
}
}
struct ContentView: View {
init() {
UICollectionView.appearance().backgroundColor = .clear
}
//...
For that purpose, I created a custom identifier 1 that hides this custom scroll background.
struct ListBackgroundModifier: ViewModifier {
@ViewBuilder
func body(content: Content) -> some View {
if #available(iOS 16.0, *) {
content
.scrollContentBackground(.hidden)
} else {
content
}
}
}
Usage:
List {
...
}
.modifier(ListBackgroundModifier())
iOS 16 adds a new API, View.scrollContentBackground, to customize background 3 colors for scrollable View
s including List
. This 2 was added in beta 3 (release notes).
List {
Text("One")
Text("Two")
Text("Three")
}
.scrollContentBackground(.red)
If you'd like to 1 make it clear, you can use Color.clear
or .hidden
like so:
.scrollContentBackground(.hidden)
As of Xcode 14.0.1 RC, the working code 1 is
.scrollContentBackground(.hidden)
.background(.purple)
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.