0

I would like to change the color of navigationTitle inside NavigationStack.

struct InterestView: View {
    var body: some View {
        NavigationStack {
            VStack {
                
            }
            .navigationTitle("interest".uppercased())
            .toolbar {
                ToolbarItemGroup(placement: .navigationBarTrailing) {
                    Button {
                        print("Image tapped!")
                    } label: {
                        Text("add".uppercased())
                            .foregroundColor(Color.primaryColor)
                            .font(.headline)
                    }
                }
            }
        }
    }
}

I could not find any modifier to change it.

softshipper
  • 32,463
  • 51
  • 192
  • 400
  • If this is for iOS then [this question](https://stackoverflow.com/questions/56505528/swiftui-update-navigation-bar-title-color) might be of interest. – Joakim Danielson Feb 16 '23 at 21:18

1 Answers1

2

In SwiftUI, you cannot change title color with a simple modifier. You need to change UINavigation Appearance but this will effect globally.

Alternative solution:

You are already using toolbar, so adding title to toolbar is easy as follow. I hope this solves your problem.

struct InterestView: View {
  var body: some View {
     NavigationStack {
        VStack {
            
        }
        .toolbar {
            ToolbarItemGroup(placement: .principal) {
                Text("interest".uppercased())
                    .foregroundColor(.red)
            }
            ToolbarItemGroup(placement: .navigationBarTrailing) {
                Button {
                    print("Image tapped!")
                } label: {
                    Text("add".uppercased())
                        .foregroundColor(Color.red)
                        .font(.headline)
                }
            }
        }
     }
  }
}
sanji_san
  • 21
  • 4