I want to change background color for full screen. I am using NavigationView
, and I want to set Gray color for background (not default white)
struct ContentView : View { var body: some View { NavigationView { ScrollView { Text("Example") } .navigationBarTitle("titl") } } }
Setting .background(Color.red)
does not work in any place.
preview
To add a screen background view by putting it at the bottom of the ZStack. Text("Hello, SwiftUI!") <1> Use ZStack so we can place a background view under the content view. <2> Use color view as background.
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.
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.
If you just embed your content in the NavigationView
within a ZStack
you should be able to throw the color in underneath your main content.
struct ContentView : View { var body: some View { NavigationView { ZStack { Color.red.edgesIgnoringSafeArea(.all) ScrollView { Text("Example") } .navigationBarTitle("title") } } } }
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