Created
October 6, 2020 04:34
-
-
Save prafullakumar/8497902d0b736e4211fa7f313fd2486f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import SwiftUI | |
public struct CirclerPercentageProgressViewStyle : ProgressViewStyle { | |
public func makeBody(configuration: LinearProgressViewStyle.Configuration) -> some View { | |
VStack(spacing: 10) { | |
configuration.label | |
.foregroundColor(Color.secondary) | |
ZStack { | |
Circle() | |
.stroke(lineWidth: 15.0) | |
.opacity(0.3) | |
.foregroundColor(Color.accentColor.opacity(0.5)) | |
Circle() | |
.trim(from: 0.0, to: CGFloat(configuration.fractionCompleted ?? 0)) | |
.stroke(style: StrokeStyle(lineWidth: 15.0, lineCap: .round, lineJoin: .round)) | |
.foregroundColor(Color.accentColor) | |
Text("\(Int((configuration.fractionCompleted ?? 0) * 100))%") | |
.font(.headline) | |
.foregroundColor(Color.secondary) | |
} | |
} | |
} | |
} | |
struct DemoPageView: View { | |
@State private var downloadAmount = 0.0 | |
var body: some View { | |
NavigationView { | |
VStack { | |
ProgressView("Downloading…", value: downloadAmount, total: 100) | |
.progressViewStyle(CirclerPercentageProgressViewStyle()) | |
.frame(width: 120, height: 120, alignment: .center) | |
.padding() | |
Button(action: { | |
withAnimation { | |
if downloadAmount < 100 { | |
downloadAmount += 10 | |
} | |
} | |
}, label: { | |
Text("+10%") | |
}) | |
} | |
.navigationBarTitle("ProgressView", displayMode: .inline) | |
} | |
} | |
} | |
struct DemoPageView_Previews: PreviewProvider { | |
static var previews: some View { | |
DemoPageView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment