I have a NavigationView with a List in it. How do I change the color of the NavigationView?
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.
tintColor is a variable in UIView that returns a color. The color returned is the first non-default value in the receiver's superview chain (starting with itself). If no non-default value is found, a system-defined color is returned (the shiny blue you always see).
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.
there is no direct api(yet) to do this, but you can look at the debug view hierarchy and you will see that it is a simple UINavigationBar and all of the old solutions would work here too(yet).
struct ContentView: View {
init(){
UINavigationBar.appearance().backgroundColor = .white
UINavigationBar.appearance().tintColor = .black
UINavigationBar.appearance().barTintColor = .black
UINavigationBar.appearance().titleTextAttributes = [.foregroundColor: UIColor.red]
UINavigationBar.appearance().largeTitleTextAttributes = [.foregroundColor: UIColor.red]
}
var body: some View {
NavigationView {
List {
Text("1")
Text("2")
Text("3")
Text("4")
}.navigationBarTitle(Text("Title With Red Color"))
}
}
}
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