Skip to content

Instantly share code, notes, and snippets.

@ericlewis
Created June 10, 2019 14:17
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 ericlewis/cbf0be7080eaf0e650e0f32146a02460 to your computer and use it in GitHub Desktop.
Save ericlewis/cbf0be7080eaf0e650e0f32146a02460 to your computer and use it in GitHub Desktop.
//
// CircularProgress.swift
// Time!
//
// Created by Eric Lewis on 6/9/19.
// Copyright © 2019 Eric Lewis, Inc. All rights reserved.
//
import SwiftUI
struct CakeView: View {
@Binding var percent: TimeInterval;
init(_ percent: Binding<TimeInterval>) {
$percent = percent
}
var body: some View {
ZStack {
Circle().stroke(Color.blue, lineWidth: 2)
GeometryReader { geometry in
Path { path in
let width: CGFloat = min(geometry.size.width, geometry.size.height)
let height = width
let middle = width / 2.0
path.move(
to: CGPoint(
x: middle,
y: height * 0.5
)
)
let middlePoint = CGPoint(
x: middle,
y: height * 0.5
)
path.addArc(center: middlePoint, radius: width * 0.45, startAngle: .degrees(-90), endAngle: .degrees(-90 + (3.6 * self.percent)), clockwise: false)
path.addLine(to: middlePoint)
path.closeSubpath()
}
.fill(Color.blue)
.aspectRatio(1, contentMode: .fit)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment