, , drawLine UIBezierPath strokePath. strokePath UIBezierPath, , . , drawLine, . , ( ), .
, drawLine, addPath(drawLine(...):
override func draw(in ctx: CGContext) {
...
while x < endx {
...
drawLine(in: ctx, x1: x, y1: y1, x2: x, y2: y2, color: color, lineWidth: lineWidth)
...
}
}
drawLine , :
func drawLine(in ctx: CGContext, x1: Int, y1: Int, x2: Int, y2: Int, color: UIColor, lineWidth: Float) {
let path = UIBezierPath()
ctx.saveGState()
ctx.setStrokeColor(color.cgColor)
ctx.setLineWidth(CGFloat(lineWidth))
path.move(to: CGPoint(x: x1, y: y1))
path.addLine(to: CGPoint(x: x2, y: y2))
ctx.addPath(path.cgPath)
ctx.strokePath()
ctx.restoreGState()
}
. , . , , setLineWidth , . , , , , , 1:

, UIView, ( UIBezierPath , CoreGraphics, @IBDesignable ..). draw(in:), , , - .