How do I change the navBar color to red in SwiftUI using an extension I want to apply to my view?
My extensions
func createToolbarSettings(dismissAction: (() -> Void)?, title: LocalizedStringKey, tag: String) -> some View {
self.toolbar(content: {
ToolbarItem(placement: .navigationBarLeading) {
Button(action: {
dismissAction?()
}, label: {
Image.arrowBack
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: .genericFrame, height: .genericFrame)
})
.tag(tag)
}
ToolbarItem(placement: .principal) {
Text(title)
.font(.montserratFontMapping(ofSize: .genericFrame, weight: .medium))
.foregroundColor(.white)
}
})
}
2
Answers
this work
For this you can create a custom modifier that applies the desired appearance to the navigation bar.You can do this by
You can then use the redNavigationBar() modifier on any view to apply the red navigation bar color.I have updated your code