Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change background color of lists in iOS15

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:

Example Image

struct ContentView: View {
    var body: some View {
        
        VStack {
            Text("Test")
            
            List {
                ForEach(1..<20) { i in
                    Text(String(i))
                }         
            }.frame(maxWidth: .infinity)                
        }       
        
    }
}
like image 763
user9582784 Avatar asked Sep 23 '21 12:09

user9582784


People also ask

How to change the background color of list in SwiftUI?

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.

How do you change the background color on a storyboard?

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.

How do I set transparent color in SwiftUI?

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.

How can I change the background color of a list?

@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?

How to hide the background of list view in iOS 16?

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.

How to change Safari background on iPhone?

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

What is scrolledgeappearance in iOS 15?

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.


1 Answers

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:

Result

like image 58
George Avatar answered Oct 26 '22 02:10

George