1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
import SwiftUI
struct ReviewContentView: View { @State private var progressExternal = 0.3 @State private var progressCentral = 0.7 @State private var progressInternal = 0.5 var body: some View { ZStack { YQProgressRingsView( progressExternal: $progressExternal, progressCentral: $progressCentral, progressInternal: $progressInternal) .aspectRatio(CGSize(width: 200, height: 200), contentMode: .fit) VStack(spacing: 10) { Spacer() Slider(value: $progressInternal, in: 0...1, step: 0.01).tint(.blue) Slider(value: $progressCentral, in: 0...1, step: 0.01).tint(.red) Slider(value: $progressExternal, in: 0...1, step: 0.01).tint(.green) } .padding(30) } } }
struct ReviewContentView_Previews: PreviewProvider { static var previews: some View { ReviewContentView() } }
struct YQProgressRing: Shape { private let startAngle = Angle.radians(1.5 * .pi) @Binding var progress: Double
func path(in rect: CGRect) -> Path { Path { path in path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: rect.width / 2, startAngle: startAngle, endAngle: startAngle + Angle(radians: 2 * .pi * progress), clockwise: false) } } }
struct YQProgressRingsView: View { private let ringPadding = 5.0 private let ringWidth = 40.0 private var ringStrokeStyle: StrokeStyle { StrokeStyle(lineWidth: ringWidth, lineCap: .round, lineJoin: .round) } @Binding var progressExternal: Double @Binding var progressCentral: Double @Binding var progressInternal: Double var body: some View { ZStack { YQProgressRing(progress: $progressInternal) .stroke(.blue, style: ringStrokeStyle) .padding(2*(ringWidth + ringPadding)) YQProgressRing(progress: $progressCentral) .stroke(.red, style: ringStrokeStyle) .padding(ringWidth + ringPadding) YQProgressRing(progress: $progressExternal) .stroke(.green, style: ringStrokeStyle) } .padding(ringWidth) } }
|