我想让用户在自定义UIView上用clearcolor作为笔触颜色。这个代码对于其他颜色都能正常工作,但是对于透明色就不行了。
override func draw(_ rect: CGRect) {
guard let context = UIGraphicsGetCurrentContext() else { return }
context.addRect(rect)
draw(inContext: context)
}
func draw(inContext context: CGContext) {
context.setLineWidth(5)
context.setStrokeColor(UIColor.clear.cgColor)
context.setLineCap(.round)
for line in lineArray {
guard let firstPoint = line.first else { continue }
context.beginPath()
context.move(to: firstPoint)
for point in line.dropFirst() {
context.addLine(to: point)
}
context.strokePath()
}
}