I have a SwiftUI view inside a NavigationStack with a custom navigation bar background color. I want the navigation bar buttons to have a consistent color throughout the app.
The issue is that the navigation bar button color changes depending on the first/root view in the body.
When the root view is a ScrollView
var body: some View {
ScrollView {
// content
}
.toolbarBackground(Color(red: 0.02, green: 0.27, blue: 0.13), for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
}
The navigation bar buttons appear white.
However, if I replace the ScrollView with a VStack, while keeping the same modifiers, the navigation bar buttons appear black:
var body: some View {
VStack {
// content
}
.toolbarBackground(Color(red: 0.02, green: 0.27, blue: 0.13), for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
}
The navigation bar buttons appear black.
How can I make the navigation bar buttons stay the same colour in both cases?