How to draw a variable width UIBezierPath?

I am wondering how I should draw the uibezierpath where the stroke width of the peaks is in the center of the arc. Here is an example of what I mean:

Curve

Either I have to go through each point when drawing, and set the stroke width accordingly, or make an easier way. Can someone point me in the right direction?

thanks

+4
source share
2 answers

You can simply draw two outer paths without a stroke, connect them, and then fill the space between them.

+6
source

Another way to try this if you're interested:

I ended up working on this by creating a loop to draw a couple of hundred line segments, and changing the line width accordingly during the drawing cycle.

To adjust the line width, I used the following function: MAX_WIDTH * sinf (M_PI * (i / NUMBER_OF_SEGMENTS)

It looks great and no performance issues as far as I can tell. It worked especially well, because I already had a list of points to use on the curve. In other cases, I suggest that it would be better to use the sosborn method.

0
source

All Articles