What is the difference between closing the bezier path using closePath function and closing it manually?

后端 未结 2 629
一个人的身影
一个人的身影 2021-02-15 10:37

I am trying to make a rectangle using UIBezierPath. I adopted two different ways to draw it. Also, I increased the stroke width to 25 px.

First method : Usin

2条回答
  •  日久生厌
    2021-02-15 11:43

    I tried your example and indeed this happens with both UIBezierPath and with simple drawing on context with CGContextAddLineToPoint.

    Can't answer your question, but it seems that adding

    bpath.lineCapStyle = kCGLineCapSquare;

    solves this exact issue. ( or the CGcontext... alternative ).

    Probably closePath takes into account the lineWidth and other line parameters to form a properly closed polygon and adjusts the path itself to be closed nicely. This becomes more probable as you delete your upper right corner ( to make it a triangle ) and notice the linecapstyle won't work anymore, only the closePath gives you a nice triangle.

提交回复
热议问题