Skip to content

Instantly share code, notes, and snippets.

@rayfix
Created June 20, 2020 21:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rayfix/651894420460161b8f2345f9e6a07b59 to your computer and use it in GitHub Desktop.
Save rayfix/651894420460161b8f2345f9e6a07b59 to your computer and use it in GitHub Desktop.
//
// 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