我希望使用SwiftUI绘制一个弧形。我正在寻找类似于在Circle()上使用的段修饰符,但我找不到。我应该能够设置起始和结束角度。
你真的应该看看这个:https://developer.apple.com/tutorials/swiftui/drawing-paths-and-shapes
这里有一个快捷方式:
import SwiftUI
struct ContentView : View {
var body: some View {
MyShape()
}
}
struct MyShape : Shape {
func path(in rect: CGRect) -> Path {
var p = Path()
p.addArc(center: CGPoint(x: 100, y:100), radius: 50, startAngle: .degrees(0), endAngle: .degrees(90), clockwise: true)
return p.strokedPath(.init(lineWidth: 3, dash: [5, 3], dashPhase: 10))
}
}
Path
来绘制弧线。let arc = UIBezierPath(arcCenter: CGPoint(x: 0, y: 0),
radius: 60,
startAngle: .pi ,
endAngle: 0.2,
clockwise: true)
那么
Path(arc.cgPath).foregroundColor(Color.blue)