Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SwiftUI: How do you change the tint color (background color) of a NavigationView?

Tags:

ios

swift

swiftui

I have a NavigationView with a List in it. How do I change the color of the NavigationView?

like image 295
Randall Stephens Avatar asked Jun 08 '19 04:06

Randall Stephens


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.

What is the tint color of a UIView?

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).

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

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"))
    }
}

}

enter image description here enter image description here enter image description here

like image 108
Farshad jahanmanesh Avatar answered Oct 12 '22 12:10

Farshad jahanmanesh