TechnologiesSwiftUI

DefaultProgressViewStyle struct

iOSmacOStvOSwatchOSvisionOSiOS 14.0+✓ renders

The default progress view style in the current context of the view being

How it works

DefaultProgressViewStyle is the progress view style that SwiftUI applies automatically when you don't supply one of your own. It conforms to ProgressViewStyle and renders a ProgressView in the platform-standard way: a determinate ProgressView with a value becomes a horizontal bar, while one without a value becomes an indeterminate spinner. Reach for it when you want to make that default appearance explicit, or to reset a view back to the system style after a custom style was applied higher in the hierarchy.

  1. Apply the style with progressViewStyle(_:)

    Every progress view style takes effect through the progressViewStyle(_:) modifier, which sets the style for the ProgressView it's attached to and any progress views below it in the hierarchy. In the example, .progressViewStyle(DefaultProgressViewStyle()) attaches the default style to the ProgressView("Loading…").

  2. Construct it with the no-argument initializer

    DefaultProgressViewStyle has a single parameterless initializer, DefaultProgressViewStyle() — it carries no configuration of its own because all of its appearance comes from the system. You instantiate it inline and hand it straight to the modifier, as the example does.

  3. Reach for it through the .automatic shorthand

    Because it's the standard style, SwiftUI exposes it as the static member .automatic, so .progressViewStyle(.automatic) on ProgressView("Downloading", value: progress) is equivalent to passing DefaultProgressViewStyle(). Prefer the dotted form for brevity; spell out the type when you want the default behavior to be unmistakable.

  4. Let determinacy choose the rendering

    The default style adapts to the ProgressView it decorates rather than to any property you set. With no value the ProgressView("Loading…") draws an indeterminate spinner, while supplying value: progress turns the ProgressView("Downloading", value: progress) into a determinate bar that fills as progress advances.

Try it — Change the value passed to the second progress view from value: progress to a fixed value: 1.0 and watch DefaultProgressViewStyle render a full bar instead of one stopped at 40%.

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.

DefaultProgressViewStyle.swift
struct DefaultProgressViewStyleDemo: View {
    @State private var progress = 0.4
    var body: some View {
        VStack(spacing: 24) {
            ProgressView("Loading…")
                .progressViewStyle(DefaultProgressViewStyle())
            ProgressView("Downloading", value: progress)
                .progressViewStyle(.automatic)
        }
        .padding()
    }
}
Live preview
Loading… Downloading
Loading… Downloading
swift → lexer → parser → sema → uiir → canvas Open in Studio ↗
What's new in SwiftUI 27 →