我有两条贝塞尔路径,想要将它们合并成一个联合体,以便我可以描边整个外形。在我的情况下,这是一个带有尾巴的对话框,虽然它不是一个复杂的形状,但使用单个路径创建它实际上会相当困难。
目前似乎没有用于创建联合体的核心图形API。我错了吗?
如果我没有错,是否有人知道可以处理这个问题的库?我已经在GitHub中搜索了,但没有找到合适的。
目前似乎没有用于创建联合体的核心图形API。我错了吗?
如果我没有错,是否有人知道可以处理这个问题的库?我已经在GitHub中搜索了,但没有找到合适的。
如果你正在处理闭合形状,UIBezierPath可以做到这一点。
UIBezierPath *firstPath = [UIBezierPath bezierPath];
// build your path
UIBezierPath *secondPath = [UIBezierPath bezierPath];
// build your path
[firstPath appendPath:secondPath];
CGPath
对象的并集,如下所示:
let path1: CGPath = ...
let path2: CGPath = ...
let combo = path1.union(path2)
func createView() -> some View {
let a = Path { path in
path.move(to: CGPoint(x: 0, y: 0))
path.addLine(to: CGPoint(x: 50, y: 100))
path.addLine(to: CGPoint(x: 100, y: 0))
}
.stroke(Color.white, style: StrokeStyle(lineWidth: 5, lineCap: .round, lineJoin: .round))
let b = RoundedRectangle(cornerRadius: 5, style: .continuous)
.fill(Color.white)
.frame(width: 30, height: 30)
.position(CGPoint.zero)
return ZStack {
a
b
}
.compositingGroup()
.colorMultiply(Color.red)
}
override func draw(_ rect: CGRect) {
super.draw(rect)
UIColor.black.setStroke()
UIColor.red.setFill()
let currentContext = UIGraphicsGetCurrentContext()
currentContext?.saveGState()
let path = drawTopView()
path.lineWidth = 5.0
path.fill()
path.stroke()
let middlepath = drawMiddleView()
middlepath.lineWidth = 2.0
middlepath.fill()
middlepath.stroke()
path.append(middlepath)
currentContext?.restoreGState()
}