How to draw variable-width UIBezierPath?

跟風遠走 提交于 2019-12-23 12:14:03

问题


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:

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 the right direction?

Thanks


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/7616861/how-to-draw-variable-width-uibezierpath

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!