【发布时间】:2017-08-27 09:07:29
【问题描述】:
我正在尝试使用UIBezierPath.append 合并两个重叠的 UIBezierPath,并且我希望填充重叠的空间。我尝试将usesEvenOddFillRule 属性设置为false,但仍然无法填充。这是问题的最小示例:
override func draw(_ rect: CGRect) {
let firstShape = UIBezierPath()
firstShape.move(to: CGPoint(x: 100, y: 100))
firstShape.addLine(to: CGPoint(x: 100, y: 150))
firstShape.addLine(to: CGPoint(x: 150, y: 170))
firstShape.close()
let secondShape = UIBezierPath(rect: CGRect(x: 125, y: 125, width: 75, height: 75))
let combined = UIBezierPath()
combined.append(firstShape)
combined.append(secondShape)
UIColor.black.setFill()
combined.fill()
}
这会产生以下形状:
我希望它是什么样子:
在一个 UIBezierPath 上使用move(to: CGPoint) 时似乎也会出现此问题。如果你在同一个 UIBezierPath 上绘制这两个形状,就会出现同样的问题。
有谁知道如何填充重叠区域?最好该解决方案在执行addClip()
【问题讨论】:
标签: swift uiview append uibezierpath