Reputation: 5621
I have a very simple NavigationStack
that I would like to customise the title, but I can't seem to find the right modifiers to achieve this.
NavigationStack {
List {
NavigationLink {
Text("My Child View")
} label: {
Label("Child View")
}
}.navigationTitle("Parent View")
}
I would like to change how the font looks for the .navigationTitle
and be able to add a button to the right. When I add a .font
modifier to .navigationTitle
it adds it to the list items, not the title. And .navigationTitle
only appears to accept a string.
I am looking to achieve the below (my button will be a + rather than a chevron).
From what I can tell, I can't use navigationTitle
to achieve this. However, if I don't use that, then the back button has the wrong title (it uses the text Back
instead of Parent View
).
Upvotes: 2
Views: 1646
Reputation: 53082
You can achieve both using the .toolbar
modifier:
public var body: some View {
NavigationStack {
List {
NavigationLink {
Text("My Child View")
} label: {
Label("Child View", systemImage: "questionmark")
}
}
.toolbar {
ToolbarItem(placement: .navigationBarLeading) {
Text("Parent View")
.font(.system(size: 22, weight: .bold))
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
} label: {
Image(systemName: "plus")
}
}
}
}
}
Upvotes: 3