Structure

ProgressView

A view that shows the progress towards completion of a task. あるビュー、それはあるタスクの完了に向けての進捗を示します。

Declaration 宣言

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

Overview 概要

Use a progress view to show that a task is making progress towards completion. A progress view can show both determinate (percentage complete) and indeterminate (progressing or not) types of progress.

Create a determinate progress view by initializing a ProgressView with a binding to a numeric value that indicates the progress, and a total value that represents completion of the task. By default, the progress is 0.0 and the total is 1.0.

The example below uses the state property progress to show progress in a determinate ProgressView. The progress view uses its default total of 1.0, and because progress starts with an initial value of 0.5, the progress view begins half-complete. A “More” button below the progress view allows the user to increment the progress in 5% increments:


@State private var progress = 0.5


VStack {
    ProgressView(value: progress)
    Button("More", action: { progress += 0.05 })
}

To create an indeterminate progress view, use an initializer that doesn’t take a progress value:


var body: some View {
    ProgressView()
}

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 {
            ProgressView(value: 0.25)
            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)
    }
}

Topics 話題

Creating an Indeterminate Progress View

Creating a Determinate Progress View

Creating a Configured Progress View

Styling Progress Views プログレスビューにスタイルをつける

Supporting Types 支援を行う型

Default Implementations 省略時実装

Relationships 関係

Conforms To 次に準拠

See Also 参照

Indicators