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.
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 theProgressView("Loading…").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.Reach for it through the .automatic shorthand
Because it's the standard style, SwiftUI exposes it as the static member
.automatic, so.progressViewStyle(.automatic)onProgressView("Downloading", value: progress)is equivalent to passingDefaultProgressViewStyle(). Prefer the dotted form for brevity; spell out the type when you want the default behavior to be unmistakable.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 supplyingvalue: progressturns theProgressView("Downloading", value: progress)into a determinate bar that fills asprogressadvances.
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.
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()
}
}