0

I tried set value to 0, -1, and 999999, and didn't work. My code:

Gauge(
   value: -1,
   label: { Text("label") },
   currentValueLabel: { Text("4") },
   minimumValueLabel: { Text("9") },
   maximumValueLabel: { Text("30") }
)
.gaugeStyle(.accessoryCircular)

Result: enter image description here

And I want to: enter image description here

Deno
  • 43
  • 6
  • 1
    Have you tried setting a `ClosedRange`? See this https://developer.apple.com/documentation/swiftui/gauge/init(value:in:label:currentvaluelabel:minimumvaluelabel:maximumvaluelabel:markedvaluelabels:) – Timmy Sep 26 '22 at 13:50

1 Answers1

0
struct CustomGaugeStyle: GaugeStyle {
    let lineWidth: Double = 5.5
    func makeBody(configuration: Configuration) -> some View {
        GeometryReader { geometry in
            ZStack {
                Circle()
                    .trim(from: 0, to: 0.75)
                    .stroke(Color(.lightGray).opacity(0.5), style: StrokeStyle(lineWidth: lineWidth, lineCap: .round, lineJoin: .round))
                    .rotationEffect(.degrees(135))
                
                Circle()
                    .trim(from: -0.3, to: 0.75 * configuration.value)
                    .stroke(Color.orange.gradient, style: StrokeStyle(lineWidth: lineWidth, lineCap: .round, lineJoin: .round))
                    .rotationEffect(.degrees(135))
                configuration.currentValueLabel
                configuration.label
                    .offset(y: 20)
            }
        }
        .aspectRatio(contentMode: .fit)
    }
}

struct CustomCircleView: View {
    @State private var innerRingFill = 50.0
    var body: some View {
        ZStack {
            Gauge(value: innerRingFill, in: 0...100) {
                Image(systemName: "gauge.medium")                    .resizable()
                    .scaledToFit()
                    .frame(width: 20, height: 15)
            } currentValueLabel: {
                Text("\(innerRingFill.formatted(.number))")
                    .font(.system(size: 17))
            }
            .frame(width: 53, height: 53)
            .gaugeStyle(CustomCircleView())
        }
    }
}

Result of code running

fish
  • 1
  • 1