With the new XCode 13 and it‘s iOS 15 support the presentation of Lists have apparently changed. Now a List has an additional gray background. Before, the background was plain white, just as I would like it to be. When I add other elements like texts, the default background color is still white.
Is there any way to get rid of the gray surrounding of the List without switching to a ForEach()
solution?
I tried changing the background color from gray to white on various places and adding additional stacks in hope to override the default background color.
This I want be be all white without the gray surrounding:
struct ContentView: View {
var body: some View {
VStack {
Text("Test")
List {
ForEach(1..<20) { i in
Text(String(i))
}
}.frame(maxWidth: .infinity)
}
}
}
We can change the background color of a list row in SwiftUI with listRowBackground(_:) modifier. To set a list row background color, add listRowBackground(_:) modifier to the list row item.
First let us see using storyboard, Open Main. storyboard and add one view to the View Controller. On the right pane you can see the property, and from there update the background color to color you want your view to be as show below.
Any SwiftUI view can be partially or wholly transparent using the opacity() modifier. This accepts a value between 0 (completely invisible) and 1 (fully opaque), just like the alpha property of UIView in UIKit.
@VladimirAmiorkov you can change the background of the list if the list style is .plain. You can do it by changing UITableView 's appearance. just put this line in Appdelegate 's didFinishLaunchingWithOptions method. In replace of UIColor.clear set whatever color you want to add in background color of list. Is there a solution for Mac for this?
iOS 16 provides a modifier to control the background visibility of List (and other scrollable views): scrollContentBackground (_:) You can hide the standard system background via .hidden. If you provide a background as well, that will become visible.
As for setting a custom iPhone Safari background, it’s a quick and easy change and you can use any of your own images or the new included background wallpapers from Apple. Open an empty Safari page (tap the two square icon > tap the + icon in bottom corner) Tap the + to use your own image or choose from one of the included background wallpapers
In iOS 15, UIKit has extended the usage of the scrollEdgeAppearance, which by default produces a transparent background, to all navigation bars. The background is controlled by when your scroll view scrolls content behind the navigation bar.
Change the listStyle
to .plain
. The default for iOS 14 is .plain
, and .insetGrouped
for iOS 15.
Code:
struct ContentView: View {
var body: some View {
VStack {
Text("Test")
List {
ForEach(1 ..< 20) { i in
Text(String(i))
}
}
.listStyle(.plain)
}
}
}
Result:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With