Created
April 2, 2020 12:21
-
-
Save KanshuYokoo/a78223ffec27319a548d52dc09b660e4 to your computer and use it in GitHub Desktop.
SwiftUI shape Example, Arc
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
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