Skip to content

Instantly share code, notes, and snippets.

@KanshuYokoo
Created April 2, 2020 12:21
Show Gist options
  • Save KanshuYokoo/a78223ffec27319a548d52dc09b660e4 to your computer and use it in GitHub Desktop.
Save KanshuYokoo/a78223ffec27319a548d52dc09b660e4 to your computer and use it in GitHub Desktop.
SwiftUI shape Example, Arc
import SwiftUI
struct ArcView: View {
var body: some View {
Arc(startAngle: .degrees(0), endAngle: .degrees(110), clockwise: true)
.stroke(Color.blue, lineWidth: 5)
.frame(width: 300, height: 300, alignment: .center)
}
}
struct Arc: Shape {
var startAngle: Angle
var endAngle: Angle
var clockwise: Bool
func path(in rect: CGRect) -> Path {
var path = Path()
path.addLines([CGPoint(x:rect.midX, y:rect.midY)])
path.addArc(center: CGPoint(x: rect.midX, y: rect.midY), radius: rect.width / 2, startAngle: startAngle, endAngle: endAngle, clockwise: clockwise)
path.addLine(to: CGPoint(x:rect.midX, y:rect.midY))
return path
}
}
struct Arc_Previews: PreviewProvider {
static var previews: some View {
ArcView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment