I have a NavigationStack that I use to move between Views in my iOS app that has some modifications done on the toolbar (Color, colorScheme, toolbar items).
To keep the same appearance on all the different views I have to define again all the different attributes in each View I reach using NavigationLinks.
Is there a way to keep what I defined in the top NavigationView across all the different views?
Code snippet below:
First View where I define the NavigationStack
NavigationStack
{
VStack{
...
}
.navigationTitle("Lavorazioni")
.navigationBarTitleDisplayMode(NavigationBarItem.TitleDisplayMode.large)
.toolbarBackground(.blue, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
.toolbar {
Button {
mostraProfilo.toggle()
} label: {
Label("User Profile", systemImage: "person.crop.circle")
}
}
Second View reached by NavigationLink in VStack
var body: some View {
VStack{
...
}
.navigationTitle("Selezione tipologia")
.toolbarBackground(.blue, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
.toolbar {
Button {
mostraProfilo.toggle()
} label: {
Label("User Profile", systemImage: "person.crop.circle")
}
}
}
Is there a way to avoid copypasting every time the following?
.toolbarBackground(.blue, for: .navigationBar)
.toolbarBackground(.visible, for: .navigationBar)
.toolbarColorScheme(.dark, for: .navigationBar)
.toolbar {
Button {
mostraProfilo.toggle()
} label: {
Label("User Profile", systemImage: "person.crop.circle")
}
}