Randall Stephens
Randall Stephens

Reputation: 1057

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

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

Upvotes: 9

Views: 3873

Answers (1)

Farshad jahanmanesh
Farshad jahanmanesh

Reputation: 885

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

Upvotes: 4

Related Questions