Created
June 20, 2020 21:42
-
-
Save rayfix/651894420460161b8f2345f9e6a07b59 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Ring | |
// | |
// Created by Ray Fix on 6/20/20. | |
// Copyright © 2020 Ray Fix. All rights reserved. | |
// | |
import SwiftUI | |
struct ActivityRing: View { | |
@Binding var progress: Double | |
var lineWidth: CGFloat = 40 | |
var gradient = Gradient(colors: [Color.blue, Color.green]) | |
var body: some View { | |
Circle() | |
.trim(from: 0, to: CGFloat(progress)) | |
.stroke( | |
AngularGradient(gradient: gradient, | |
center: .center, | |
endAngle: .degrees(360*progress)), | |
style: .init(lineWidth: lineWidth, lineCap: .round)) | |
.overlay( | |
GeometryReader { proxy in | |
Circle() | |
.fill(self.gradient.stops.last!.color) | |
.offset(x: proxy.size.width/2) | |
.rotationEffect(.degrees(360*self.progress)) | |
.frame(width: self.lineWidth) | |
} | |
) | |
.rotationEffect(.degrees(-90)) | |
.scaledToFit() | |
.padding(lineWidth/2) | |
} | |
} | |
struct ContentView: View { | |
@State private var progress: Double = 0.3 | |
var body: some View { | |
VStack { | |
ActivityRing(progress: $progress) | |
Slider(value: $progress, in: 0...10) | |
}.padding() | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment