Initializer

init(value:in:label:)

Creates a gauge showing a value within a range and describes the gauge’s purpose and current value.

Declaration 宣言

init<V>(value: V, in bounds: ClosedRange<V> = 0...1, label: () -> Label) where CurrentValueLabel == EmptyView, BoundsLabel == EmptyView, MarkedValueLabels == EmptyView, V : BinaryFloatingPoint

Parameters パラメータ

value

The value to show in the gauge.

bounds

The range of the valid values. Defaults to 0...1.

label

A view that describes the purpose of the gauge.

Discussion 議論

Use this modifier to create a gauge that shows the value at its relative position along the gauge and a label describing the gauge’s purpose. In the example below, the gauge has a range of 0...1, the indicator is set to 0.4, or 40 percent of the distance along the gauge:


struct SimpleGauge: View {
    @State private var batteryLevel = 0.4


    var body: some View {
        Gauge(value: batteryLevel) {
            Text("Battery Level")
        }
    }
}

A linear gauge that shows an indicator at 40 percent along the length