How it works
ToolbarTitleDisplayMode is the type that describes how a navigation bar presents its title — whether the title appears large and prominent, condensed inline next to the bar's controls, or sized automatically by the platform. It gives you explicit control over a placement decision that SwiftUI otherwise makes for you based on context and scroll position. Reach for it when a screen needs a title style that differs from the default — for example, keeping a title compact even at the top of a scrollable list, or forcing a large treatment where the system would collapse it.
Provide a title for the bar with
navigationTitle(_:)ToolbarTitleDisplayModeonly has meaning once there is a title to display, so the view first declares one. Here.navigationTitle("Mail")supplies the string that the toolbar will render, and the display mode then governs how that string is laid out.Apply the mode with
toolbarTitleDisplayMode(_:)The
toolbarTitleDisplayMode(_:)modifier is how you attach aToolbarTitleDisplayModeto the surrounding navigation hierarchy. In the example it is placed on theListinside aNavigationStack, setting the policy for that destination's title.Choose a presentation case
ToolbarTitleDisplayModeexposes its values as static members you pass to the modifier:.automaticdefers to the platform,.largekeeps the title big, and.inlinekeeps it condensed in the bar. The example selects.inlineLarge, a hybrid that shows the title inline while preserving the visual weight of the large style.Scope the mode to a navigation container
Because the modifier reads from the navigation environment,
ToolbarTitleDisplayModetakes effect within the enclosingNavigationStack(orNavigationSplitView). Attaching it to the content of the stack, as the demo does on theList, applies the chosen mode to that screen's title rather than globally.
.toolbarTitleDisplayMode(.inlineLarge) to .toolbarTitleDisplayMode(.inline) and then .large to watch the "Mail" title shift between a condensed bar title and a full large title.Example & preview
Press Run live & edit to compile it in your browser — then edit the Swift on the left and the preview re-renders live.
struct ToolbarTitleDisplayModeDemo: View {
var body: some View {
NavigationStack {
List {
Text("Inbox")
Text("Sent")
Text("Drafts")
}
.navigationTitle("Mail")
.toolbarTitleDisplayMode(.inlineLarge)
}
}
}