跳转至
Structure

ProgressView

An animated loading bar or "spinner" shown when an ongoing task has started but is not yet complete

Declaration

struct ProgressView<Label, CurrentValueLabel> : View where Label : View, CurrentValueLabel : View

Overview

A progress view is a combination of UIProgressView and UIActivityIndicatorView from UIKit. When initialized without arguments, it resembles a “spinner”.

struct ContentView: View {
    var body: some View {
        ProgressView()
    }
}
A gif displaying a default gray circular style progress view spinning.

When initialized with a value ProgressView looks like a loading bar that fills up from left to right.

struct ContentView: View {
    var body: some View {
        ProgressView(value: 0.5)
    }
}
A ProgressView displaying a gray loading bar filled halfway left to right by blue, as defined by the ProgressView value being 0.5.

ProgressView has many custom initializers, differing in the label type and whether it is a spinner or a linear progress bar. Explore them in the sidebar.

Styling Progress Views

You can customize the appearance and interaction of progress views by creating styles that conform to the ProgressViewStyle protocol. To set a specific style for all progress view instances within a view, use the progressViewStyle(_:) modifier. In the following example, a custom style adds a dark blue shadow to all progress views within the enclosing VStack:

struct ShadowedProgressViews: View {
    var body: some View {
        VStack(spacing: 50) {
            ProgressView()
            ProgressView(value: 0.75)
        }
        .progressViewStyle(DarkBlueShadowProgressViewStyle())
    }
}

struct DarkBlueShadowProgressViewStyle: ProgressViewStyle {
    func makeBody(configuration: Configuration) -> some View {
        ProgressView(configuration)
            .shadow(color: Color(red: 0, green: 0, blue: 0.6),
                    radius: 4.0, x: 1.0, y: 2.0)
    }
}
A gif showing a view with a VStack containing a ProgressView with a custom style; a circular gray progress spinner sits above a progress bar filled 75% by a dark blue bar with a dramatic shadow.

Availability

iOS 14.0+

macOS 11.0+

tvOS 14.0+

watchOS 7.0+

Topics


Initializer

init() Creates a progress spinner.

init(_:) Creates a progress bar from a Progress object.

init(_:) Creates a progress spinner from a string title.

init(_:) Creates a progress view based on a style configuration.

init(_:) Creates a progress spinner from a localized string key title.

init(_:value:total:) Creates a progress bar from a value, a total, and a title string.

init(_:value:total:) Creates a progress bar from a value, a total, and a localized string key.

init(label:) Creates a progress spinner from a custom label.

init(value:total:) Creates a progress bar from a value and a total.

init(value:total:label:) Creates a progress bar from a value, a total, and a custom label.

init(value:total:label:currentValueLabel:) Creates a progress bar from a value, a total, a custom label, and a custom label for the current value.


Instance Property

body The content and behavior of the view.


Type Alias

Body The type of view representing the body of this view.