[英]How to draw an arc with SwiftUI?
我想用 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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.