SwiftUI continues to improve the way developers build native Apple applications. With iOS 27.2, Apple introduces toolbarTitleAlignment, a new view modifier that gives developers more control over the positioning of navigation bar titles.
In this tutorial, we’ll explore how to use toolbarTitleAlignment in SwiftUI, understand its available alignment options, and implement practical examples using Swift and Xcode 27.
Whether you’re an experienced iOS Developer or just getting started with Apple’s development ecosystem, this new modifier makes navigation bar customization simpler and more intuitive.
What Is toolbarTitleAlignment in SwiftUI?
The toolbarTitleAlignment(_:) modifier allows you to specify the preferred alignment of a navigation bar’s title.
Previously, developers often had to use custom toolbar items, particularly ToolbarItem(placement: .principal), to achieve a specific title position. Although this approach remains useful for custom navigation bar content, the new modifier provides a more straightforward solution when you simply want to control title alignment.
The API is designed to work with SwiftUI navigation containers, such as NavigationStack, and integrates with the existing navigation title configuration.
Its main advantage is simplicity: you can change the title alignment directly through a dedicated modifier without creating additional toolbar components.
Requirements: iOS 27.2 and Xcode 27
To use toolbarTitleAlignment, you’ll need:
- Xcode 27 with the appropriate iOS 27.2 SDK.
- An application targeting iOS 27.2 or later to use the API without availability checks.
- A SwiftUI project using a navigation container such as
NavigationStack.
The new modifier is available from iOS 27.2, so applications supporting earlier versions should consider using availability checks or an alternative implementation.
How to Use toolbarTitleAlignment
Let’s start with a basic example.
First, create a NavigationStack and configure its navigation title. Then apply the new modifier to the view.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
Text("Welcome to my app")
.navigationTitle("My Title")
.toolbarTitleDisplayMode(.inline)
.toolbarTitleAlignment(.center)
}
}
}
In this example, the navigation bar displays the title “My Title” in the center.
The important line is:
.toolbarTitleAlignment(.center)
This tells SwiftUI to prefer a centered navigation bar title.
Notice that we also use .toolbarTitleDisplayMode(.inline). This controls how the navigation title is displayed, while toolbarTitleAlignment controls its preferred alignment. They serve different purposes and can be combined.
Available toolbarTitleAlignment Options
The new API provides three alignment options that let you adapt the navigation bar to your application’s design.
1. Center Alignment
.toolbarTitleAlignment(.center)
The .center option positions the navigation title in the center of the navigation bar.
This is particularly useful for applications that use a traditional centered navigation title or want a balanced interface.
2. Leading Alignment
.toolbarTitleAlignment(.leading)
The .leading option positions the title towards the leading edge of the navigation bar.
For left-to-right languages, this generally means aligning the title to the left. For right-to-left languages, the leading edge follows the system’s layout direction.
This option is useful for applications that prefer a more editorial or content-focused navigation design.
3. Automatic Alignment
.toolbarTitleAlignment(.automatic)
The .automatic option allows the system to determine the preferred title alignment based on the navigation context and toolbar configuration.
This is the default choice when you want to preserve the platform’s standard navigation behavior.
Complete Example With a Leading-Aligned Title
Here is another practical implementation using a leading-aligned title and a toolbar button.
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationStack {
VStack(spacing: 20) {
Text("Explore the latest features")
.font(.title2)
Text("Customize your navigation experience.")
.foregroundStyle(.secondary)
}
.padding()
.navigationTitle("Discover")
.toolbarTitleDisplayMode(.inline)
.toolbarTitleAlignment(.leading)
.toolbar {
ToolbarItem(placement: .topBarTrailing) {
Button("Edit") {
print("Edit tapped")
}
}
}
}
}
}
This example creates a navigation bar with a leading-aligned title and an Edit button on the trailing side.
Is toolbarTitleAlignment Better Than ToolbarItem Principal?
For straightforward title alignment, toolbarTitleAlignment is the simpler approach.
Using ToolbarItem(placement: .principal) is still valuable when you need to replace the standard title with custom content, such as a logo, a search field, or a more complex view.
The new modifier focuses specifically on alignment, keeping your navigation code cleaner and easier to maintain.
Conclusion
The introduction of toolbarTitleAlignment in iOS 27.2 is a welcome improvement for SwiftUI developers. It provides a native and convenient way to control navigation bar title positioning using .automatic, .center, and .leading.
For every iOS Developer working with Swift, Xcode 27 and modern SwiftUI applications, this small API addition offers another useful tool for building polished, consistent navigation experiences with less code.