跳转至
Protocol

ProgressViewStyle

A type that applies standard interaction behavior to all progress views within a view hierarchy.

Declaration

protocol ProgressViewStyle

Overview

Use this protocol to create custom and reusable styles for your ProgressViews.

You can either use a predefined style or create your own style

Predefined Styles

There are 3 predefined ProgressView styles in SwiftUI:

To use one of these styles, pass an instance to progressViewStyle(_:):

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

Custom Styles

To create a custom ProgressViewStyle, create a structure that implements the makeBody(configuration:):

 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)
     }
 }
Then apply it to a ProgressView using progressViewStyle(_:):

 struct ShadowedProgressViews: View {
     var body: some View {
         VStack(spacing: 50) {
             ProgressView()
             ProgressView(value: 0.75)
         }
         .progressViewStyle(DarkBlueShadowProgressViewStyle())
     }
 }
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


Type Alias

Configuration A type alias for the properties of a progress view instance.


Instance Method

makeBody(configuration:) Creates a view representing the body of a progress view.


Associated Type

Body A view representing the body of a progress view.