TechnologiesSwiftUI

DefaultShareLinkLabel struct

iOSmacOStvOSwatchOSvisionOS✓ renders

The default label used for a share link.

How it works

DefaultShareLinkLabel is the view that a ShareLink presents when you don't supply a label of your own. It packages the system's standard sharing affordance — the share glyph paired with a localized title — so that every ShareLink looks and behaves the way people expect, without you assembling that content by hand. Reach for it implicitly whenever you create a ShareLink and want the familiar platform appearance rather than a custom label, and rely on it as the fallback that keeps sharing controls consistent across your app and the rest of the system.

  1. Get the default label by omitting the closure

    A ShareLink renders DefaultShareLinkLabel automatically when you give it something to share but no label content. In the example, ShareLink(item: URL(string: "https://www.apple.com")!) with an empty trailing closure leaves SwiftUI to supply the default label rather than a view you built.

  2. Let a title customize the default label's text

    Passing a title string still produces the default label, but with your wording in place of the standard text while keeping the system share glyph and styling. The ShareLink("Share Apple", item:) form shows "Share Apple" drawn by DefaultShareLinkLabel instead of the generic title.

  3. Supply the item the label points at

    The default label always reflects what the link will share, so the item: argument is what gives it meaning. Here the same URL(string: "https://www.apple.com")! is the payload behind both links, and DefaultShareLinkLabel presents the control that offers that URL to the share sheet.

  4. Treat the default label as an ordinary view

    Because DefaultShareLinkLabel is a real view, the ShareLink that contains it accepts the usual layout and styling modifiers. Applying .padding() to the second ShareLink spaces the default label like any other control, without you reconstructing its glyph or text.

Try it — Replace the empty closure in ShareLink(item: URL(string: "https://www.apple.com")!) with { Label("Send Link", systemImage: "paperplane") } to see your own label take over from DefaultShareLinkLabel.

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.

DefaultShareLinkLabel.swift
struct DefaultShareLinkLabelDemo: View {
    var body: some View {
        ShareLink(item: URL(string: "https://www.apple.com")!) {
            // omit this closure and ShareLink supplies a DefaultShareLinkLabel
        }
        ShareLink("Share Apple", item: URL(string: "https://www.apple.com")!)
            .padding()
    }
}
Live preview
Share
Share
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →