How to create a custom reusable toolbar in SwiftUI
Learn how to abstract and reuse a SwiftUI toolbar across multiple screens.
12 Aug 2025 · 3 min read
When building navigation bars and toolbars in SwiftUI, we'll often want to keep the same look and functionality across multiple screens. Instead of copying and pasting the same toolbar code everywhere, we can abstract the toolbar into a reusable component.
SwiftUI's ToolbarContent protocol is perfect to do that. In this guide, we'll create a custom reusable toolbar, apply it via a ViewModifier, and add a convenient view extension for a one-line API.

The following example creates a navigation bar with a custom back button and a title:
struct SomeCustomToolBarContent: ToolbarContent {let title: String@Environment(\.presentationMode) var presentationModevar body: some ToolbarContent {ToolbarItemGroup(placement: .navigationBarLeading) {Button(action: {presentationMode.wrappedValue.dismiss()}) {Image("someCustomBackButtonImage")}}ToolbarItem(placement: .principal) {Text(title).font(titleFont).foregroundColor(titleColor)}}}
To use it, we can use SwiftUI's toolbar modifier as follows:
someView.toolbar {SomeCustomToolBarContent(title: "SomeTitle")}.navigationBarBackButtonHidden(true).navigationBarShadow()
We can go a step further to add even more abstraction by creating a custom view modifier:
struct SomeCustomToolBarModifier: ViewModifier {let title: Stringfunc body(content: Content) -> some View {return content.toolbar {SomeCustomToolBarContent(title: title)}.navigationBarBackButtonHidden(true).navigationBarShadow()}}
With that in place, we can now apply the toolbar as follows:
someView.modifier(SomeCustomToolBarModifier(title: "SomeTitle"))
To make the call above even shorter, we could additionally create a View extension:
extension View {func someCustomToolbar(title: String) -> some View {return self.modifier(SomeCustomToolBarModifier(title: title))}}
Now, we are able to apply the toolbar with the following call:
someView.someCustomToolbar(title: "SomeTitle")



Newsletter
Like to support my work?
Say hi
Related tags
Articles with related topics
Latest articles and tips



