在UIKit中绘制一个冲程&;填充路径/形状非常简单.
例如,下面的代码画了一个红色圆圈,用蓝色划过.
override func draw(_ rect: CGRect) {
guard let ctx = UIGraphicsGetCurrentContext() else { return }
let center = CGPoint(x: rect.midX, y: rect.midY)
ctx.setFillColor(UIColor.red.cgColor)
ctx.setStrokeColor(UIColor.blue.cgColor)
let arc = UIBezierPath(arcCenter: center, radius: rect.width/2, startAngle: 0, endAngle: CGFloat.pi * 2, clockwise: true)
arc.stroke()
arc.fill()
}
如何使用SwiftUI实现这一点?
Swift UI似乎支持:
Circle().stroke(Color.blue)
// and/or
Circle().fill(Color.red)
但不是
Circle().fill(Color.red).stroke(Color.blue) // Value of type 'ShapeView<StrokedShape<Circle>, Color>' has no member 'fill'
// or
Circle().stroke(Color.blue).fill(Color.red) // Value of type 'ShapeView<Circle, Color>' has no member 'stroke'
我应该只画两个圆圈吗?这似乎有点傻.