Logo for tanaschita.com

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.

Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE

The following example creates a navigation bar with a custom back button and a title:

struct SomeCustomToolBarContent: ToolbarContent {
let title: String
@Environment(\.presentationMode) var presentationMode
var 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: String
func 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")
Sponsorship logo
Preparing for a technical iOS job interview
Preparing for a technical iOS Job Interview with over 300 questions & answers. Covering Swift & Objective-C, SwiftUI & UIKit, Combine, HTTP Networking, iOS File System, Core Data, Concurrency with async/await, Security, Automated Testing, Dependency Management, AI & Machine Learning and more.
LEARN MORE
Sponsorship logo
Architecture & Design Patterns for iOS
This book is a practical guide to essential architectural principles and design patterns for iOS development. It covers strategies for building maintainable apps with Swift and SwiftUI, including dependency injection, navigation, common patterns, and modularization.
LEARN MORE
Sponsorship logo
Become a sponsor of tanaschita.com
By publishing an article on different iOS topics every week, tanaschita.com is constantly growing in the developer community and may provide a great audience for you as a sponsor.
CLICK TO LEARN MORE

Newsletter

Image of a reading marmot
Subscribe

Like to support my work?

Say hi

Related tags

Articles with related topics

swiftui

property wrappers

swift

ios

Presenting alerts and confirmation dialogs from identifiable data in SwiftUI

Learn how to present alerts and confirmation dialogs using optional identifiable items instead of Boolean state.

24 Aug 2026 · 4 min read

Latest articles and tips

© 2026 tanaschita.com

Privacy policy

Impressum