How do I set a view's background to the gray'ish one in SwiftUI?

Viewed 1125

I noticed that whenever I create a view it automatically gets a white background color. If you insert a list however, no matter the size, the entire view seems to get a sort of grey background, which looks better to me than a white background. I'm wondering how I can get my background to look like this (without using a list, or an invisible dummy list maybe)? I've already tried getting the color code but that just gives me a dark grey background. I tried adjusting the opacity but it just isn't the same as the native one. enter image description here

edit: It appears the size of the list does matter, it seems to have something to do with NavigationViews and NavigationLinks

1 Answers

That is the default group table view background color (systemGroupedBackground) with the color code #F2F2F7. You can use it as a background color like this:

.background(Color(red: 0.949, green: 0.949, blue: 0.97, opacity: 1.0))

...or simply:

.background(Color(.systemGroupedBackground))

Keep in mind that with the latter solution, the color might change in later iOS versions if Apple decides to change the value of the constant.

Related