Created
February 17, 2021 00:34
-
-
Save aessam/af37e980d91d23b6b992f992e7fd0c1a to your computer and use it in GitHub Desktop.
Drawing segments of a circle in SwiftUI
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 | |
extension Color { | |
static var random: Color { | |
return Color( | |
red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...1) | |
) | |
} | |
} | |
struct ContentView: View { | |
@State var sections: Double = 3 | |
var body: some View { | |
Slider(value: $sections, in: 2...20, step: 1) | |
ZStack { | |
ForEach(0..<20) { index in | |
Circle() | |
.trim(from: 0.017, to: (1/CGFloat(sections)) - (0.017)) | |
.rotation(.degrees(Double(CGFloat(index) * CGFloat(360/sections)))) | |
.rotation(.degrees(-90)) | |
.stroke(Color.random ,style: StrokeStyle(lineWidth: 50, lineCap: .round)) | |
.frame(width: 520, height: 520) | |
} | |
Circle() | |
.frame(width: 425, height: 425) | |
Text("") | |
.font(.system(size: 420, weight: .light, design: .serif)) | |
.foregroundColor(.black) | |
}.padding(50) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment