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