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.
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.Use it as a button's label
Because it is just a view, it slots naturally into the
label:closure of aButton, supplying the visible content while your action closure performs the work. Here it fills the trailinglabel:ofButton { ... } label: { DefaultNewDocumentButtonLabel() }, leaving the empty action body as the place to create the document.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 theButtonrenders DefaultNewDocumentButtonLabel inside a prominent bordered control without changing how you construct the label itself.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
VStacknext to aText("New Document Button"), where the symbol is the button's content and the stack andTextare only the surrounding placement.
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.
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()
}
}