开发者

How to draw variable-width UIBezierPath?

开发者 https://www.devze.com 2023-04-10 10:44 出处:网络
I\'m wondering how I should go about drawing a uibezierpath where the stroke width peaks at the center of the arc. Here\'s an example of what I mean:

I'm wondering how I should go about drawing a uibezierpath where the stroke width peaks at the center of the arc. Here's an example of what I mean:

How to draw variable-width UIBezierPath?

Either I have to go through each point when drawing, and set the stroke width accordingly, or there's an easier way. Can anyone point me in 开发者_JS百科the right direction?

Thanks


You can just draw the two outer paths with no stroke, join them, and then fill in the space between them.


Another way to try this if you're interested:

I ended up getting this to work by creating a loop to draw a couple hundred line segments, and changing the line width accordingly during the draw loop.

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

Looks great and no performance issues as far as I can tell. Worked out particularly well because I already had a list of the points to use on the curve. For other cases I'm guessing it would be better to use sosborn's method.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号