TechnologiesSwiftUI

DefaultNewDocumentButtonLabel struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default label used for a new document button.

How it works

DefaultNewDocumentButtonLabel is a view that renders the system-standard label SwiftUI uses for a "create new document" control. It gives you the platform's idiomatic text and imagery for starting a document, so a button you build by hand reads and behaves like the one the framework provides in document-based apps. Reach for it whenever you place your own new-document action outside the automatic document UI and want it to match the system's wording and presentation across OS versions and locales.

  1. Instantiate DefaultNewDocumentButtonLabel as a view

    DefaultNewDocumentButtonLabel conforms to View and is created with its no-argument initializer, so you drop it anywhere a view is expected. In the example it appears as DefaultNewDocumentButtonLabel(), producing the standard new-document label with no further configuration.

  2. Use it as a button's label

    Because it is just a view, it slots naturally into the label: closure of a Button, supplying the visible content while your action closure performs the work. Here it fills the trailing label: of Button { ... } label: { DefaultNewDocumentButtonLabel() }, leaving the empty action body as the place to create the document.

  3. Let the surrounding button style it

    The label inherits styling from its enclosing button, so the same standard content adapts to whatever button treatment you apply. Applying .buttonStyle(.borderedProminent) to the Button renders DefaultNewDocumentButtonLabel inside a prominent bordered control without changing how you construct the label itself.

  4. Compose it like any other label view

    Since it is an ordinary view, it participates in normal layout and modifier composition alongside neighboring content. In the example it sits inside a VStack next to a Text("New Document Button"), where the symbol is the button's content and the stack and Text are only the surrounding placement.

Try it — Replace DefaultNewDocumentButtonLabel() with Text("New") and compare the rendered button to see the standard label's system-provided wording and imagery that the symbol supplies for free.

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.

DefaultNewDocumentButtonLabel.swift
struct DefaultNewDocumentButtonLabelDemo: View {
    var body: some View {
        VStack(alignment: .leading, spacing: 16) {
            Text("New Document Button")
                .font(.headline)
            Button {
                // create a new document
            } label: {
                DefaultNewDocumentButtonLabel()
            }
            .buttonStyle(.borderedProminent)
        }
        .padding()
    }
}
Live preview
New Document Button
New Document Button
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →