TechnologiesSwiftUIToolbars and Commands

ContentToolbarPlacement struct

iOSmacOStvOSwatchOSvisionOSiOS 18.4+✓ renders

A structure that specifies where toolbar content is placed.

How it works

ContentToolbarPlacement is a structure that identifies a region of the toolbar associated with a view's content, as distinct from the navigation bar or other system-managed areas. You use it with toolbar modifiers to scope changes — such as showing, hiding, or removing toolbar elements — to the content-bearing portion of a container like a List inside a NavigationStack. Reach for it when you need to address the content toolbar specifically rather than the whole toolbar surface, for example to suppress an automatically supplied title.

  1. Identify the structure and its role

    ContentToolbarPlacement names the content area of a toolbar so that toolbar APIs can target it. It conforms to the placement protocols SwiftUI uses to route toolbar items and configuration, letting you speak about "the content toolbar" rather than an unscoped toolbar. In the example it underlies the placement that the .toolbar(removing:) modifier operates against for the List content.

  2. Attach it through a toolbar modifier

    You apply a ContentToolbarPlacement indirectly by passing a default toolbar element to a toolbar modifier on a content view. Here .toolbar(removing: .title) is attached to the List, telling SwiftUI to act on that view's content toolbar instead of leaving its default decorations in place.

  3. Choose the element to affect with .title

    The .title value designates the default title element that the content toolbar provides. Combined with the placement, it pinpoints exactly what changes — in this case the navigation title contributed by .navigationTitle("Mail") — so the removal is precise rather than wholesale.

  4. Anchor it inside a navigation container

    Content toolbar placement is meaningful only where a container supplies a toolbar, so the affected view lives inside a NavigationStack. The List of Text("Inbox"), Text("Sent"), and Text("Drafts") is the content whose toolbar the placement refers to; the surrounding stack is simply where the symbol plugs in.

Try it — Remove the .toolbar(removing: .title) line and the title "Mail" reappears, showing that the modifier was acting on the content toolbar's .title element.

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.

ContentToolbarPlacement.swift
struct ContentToolbarPlacementDemo: View {
    var body: some View {
        NavigationStack {
            List {
                Text("Inbox")
                Text("Sent")
                Text("Drafts")
            }
            .navigationTitle("Mail")
            .toolbar(removing: .title)
        }
    }
}
Live preview
Inbox Sent Drafts 9:41 Mail
Inbox Sent Drafts 9:41 Mail
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →