iosobjective-cdrawrectcgcontextcgcontextdrawpath

CGContext draw 45 degree line joint


Is there any way to draw lines in CGContext which connected with each other with 45 degree angle, like this picture shows: enter image description here


Solution

  • I don't think there is a simple way to do it. If there were, it would be one of the options you could pass to CGContextSetLineCap, but it only supports Butt, Round, and Square.

    What you would need to do is write a function that takes two end points, a direction (so you know which side to make smaller), and a color. Use this info to draw a filled-in trapezoid.