TechnologiesSwiftUI

SpringLoadingBehavior struct

iOSmacOStvOSwatchOSvisionOSiOS 17.0+✓ renders

The options for controlling the spring loading behavior of views.

How it works

SpringLoadingBehavior describes whether a control activates when a drag hovers over it long enough — the "spring-loading" gesture that lets someone open a folder, switch a tab, or trigger a button mid-drag without dropping what they're carrying. SwiftUI exposes the behavior as a small value type with named cases that you attach to a view rather than wiring up timers or hover tracking yourself. Reach for it when a control should respond during a drag-and-drop interaction, or when you want to explicitly opt a control in or out of that automatic activation.

  1. Choose a behavior case

    SpringLoadingBehavior is a struct that vends a handful of static values describing how the control reacts to a hovering drag. The example uses .enabled to say the control should spring-activate; the type also offers .automatic (defer to the system default for the control kind) and .disabled (never spring-load), letting you state intent precisely.

  2. Apply it with springLoadingBehavior(_:)

    You install the behavior by calling the .springLoadingBehavior(_:) view modifier, passing the case you chose. In the example, .springLoadingBehavior(.enabled) is attached to the Button, marking that button as a valid spring-loading target during a drag.

  3. Attach it to an activatable control

    Spring loading is meaningful on controls that perform an action or change selection, so the modifier sits on the Button here — the Label("Documents", systemImage: "folder") content is exactly the kind of destination a user might want to trigger while dragging files toward it. The behavior plugs into the control; the surrounding VStack and caption Text are just there to frame it.

  4. Let it cascade through the environment

    The modifier writes into the environment, so applying .springLoadingBehavior to a container propagates the value to the controls inside it, while a more deeply nested modifier overrides it. Setting it directly on the Button, as in the example, scopes the .enabled value to just that control.

Try it — Change .springLoadingBehavior(.enabled) to .springLoadingBehavior(.disabled) and drag over the button — it will no longer spring-activate, isolating exactly what the behavior controls.

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.

SpringLoadingBehavior.swift
struct SpringLoadingBehaviorDemo: View {
    var body: some View {
        VStack(spacing: 20) {
            Text("Spring Loading")
                .font(.headline)
            Button {
            } label: {
                Label("Documents", systemImage: "folder")
            }
            .buttonStyle(.borderedProminent)
            .springLoadingBehavior(.enabled)
            Text("Hover a drag over this button to spring-activate it.")
                .font(.caption)
                .foregroundStyle(.secondary)
                .multilineTextAlignment(.center)
        }
        .padding()
    }
}
Live preview
Spring Loading Documents Hover a drag over this button to spring-activate it.
Spring Loading Documents Hover a drag over this button to spring-activate it.
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →