Last active
January 19, 2019 18:10
-
-
Save almaleh/2f94fdd6f17d691ff32d0bcb792a2dd6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override func draw(_ layer: CALayer, in ctx: CGContext) { | |
// 1 | |
let drawingLayer = self.drawingLayer ?? CAShapeLayer() | |
// 2 | |
drawingLayer.contentsScale = UIScreen.main.scale | |
// 3 | |
let linePath = UIBezierPath() | |
// 4 | |
for (index, point) in line.enumerated() { | |
if index == 0 { | |
linePath.move(to: point) | |
} else { | |
linePath.addLine(to: point) | |
} | |
} | |
drawingLayer.path = linePath.cgPath | |
drawingLayer.opacity = 1 | |
drawingLayer.lineWidth = lineWidth | |
drawingLayer.lineCap = .round | |
drawingLayer.fillColor = UIColor.clear.cgColor | |
drawingLayer.strokeColor = lineColor.cgColor | |
// 5 | |
if self.drawingLayer == nil { | |
self.drawingLayer = drawingLayer | |
layer.addSublayer(drawingLayer) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment