title: How can I change the background color of the navigation bar in SwiftUI?
body: <p>I would like to change the background color of the navigation bar. But what am I doing wrong that the colors look so different?</p>
  
  <p><a href="https://i.stack.imgur.com/tdh1R.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tdh1R.png" alt="enter image description here"></a></p>
  
  <p>My code:</p>
  
  <pre><code>UINavigationBar.appearance().backgroundColor = .red
  
  return VStack(spacing: 0) {
      Text("Test")
          .padding(.top, 9.5)
          .padding(.bottom, 8)
          .frame(minWidth: 0, maxWidth: .infinity)
          .background(Color.red)
          .font(.footnote)
      NavigationView {
          Text("Hello")
          .navigationBarTitle(Text("Hi"), displayMode: .inline)
      }
  }
  </code></pre>
  
  <p><br>
  <b>EDIT:</b>
  With <a href="https://stackoverflow.com/a/58427754/3088606">this solution</a>, it gets better but there is still a difference in color.
  <a href="https://i.stack.imgur.com/KxmCP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KxmCP.png" alt="enter image description here"></a></p>
  
  <p>My code now:</p>
  
  <pre><code>struct ContentView: View {
      var body: some View {
          VStack(spacing: 0) {
              Text("Test")
                  .padding(.top, 9.5)
                  .padding(.bottom, 8)
                  .frame(minWidth: 0, maxWidth: .infinity)
                  .background(Color("red")) // Now I use a color set
                  .font(.footnote)
              NavigationView {
                  Text("Hello")
                  .navigationBarTitle(Text("Hi"), displayMode: .inline)
                  .background(NavigationConfigurator { nc in
                      nc.navigationBar.barTintColor = UIColor(named: "red") // Now I use a color set
                  })
              }
          }
      }
  }
  
  struct NavigationConfigurator: UIViewControllerRepresentable {
      var configure: (UINavigationController) -&gt; Void = { _ in }
  
      func makeUIViewController(context: UIViewControllerRepresentableContext&lt;NavigationConfigurator&gt;) -&gt; UIViewController {
          UIViewController()
      }
      func updateUIViewController(_ uiViewController: UIViewController, context: UIViewControllerRepresentableContext&lt;NavigationConfigurator&gt;) {
          if let nc = uiViewController.navigationController {
              self.configure(nc)
          }
      }
  }
  </code></pre>