Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How change background color if using NavigationView in SwiftUI?

Tags:

swift

swiftui

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

like image 291
Ivan Vorobei Avatar asked Jul 07 '19 15:07

Ivan Vorobei


People also ask

How do I change the background color in SwiftUI?

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.

How do I change the background color on a storyboard in Swift?

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 change the color of a 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.


1 Answers

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")             }         }     } } 
like image 176
LJ White Avatar answered Oct 05 '22 18:10

LJ White