简体   繁体   English

如何快速绘制复杂的圆?

[英]How to draw a complex circle in swift?

I have looked how to draw simple shapes by using drawRect and NSBezierPath, but I need to draw a complex circle. 我已经看过如何使用drawRect和NSBezierPath绘制简单的形状,但是我需要绘制一个复杂的圆。 So, I have attributedstring and some ranges of the string have different colors. 因此,我有attributedstring,并且字符串的某些范围具有不同的颜色。 I need to make a circle having length of the string and different ranges of the string should be marked as arrows, see example below. 我需要制作一个具有字符串长度的圆,并将字符串的不同范围标记为箭头,请参见下面的示例。 To have all parts of the circle proportional to the string I can use lengths of the string and ranges. 为了使圆的所有部分与字符串成比例,我可以使用字符串的长度和范围。 But, how can I draw different segments of the circle? 但是,如何绘制圆的不同部分? By using multiple subpaths for each segment or ? 通过为每个段或?使用多个子路径

Update The figure should represent the changing attributedstring, ie user can change color of region, length of the marked region, length of the string, can add new marked region or delete the marked region, and by clicking the button should get the graphical representation of the string. 更新该图应代表变化的属性字符串,即用户可以更改区域的颜色,标记区域的长度,字符串的长度,可以添加新标记区域或删除标记区域,并且通过单击按钮应获得图形的字符串。 I was thinking to use the array of Ranges for the attributedstring, and in for-loop these Ranges one by one should be used to draw Arcs with and without arrow heads to fill the whole ring. 我当时在考虑为属性字符串使用Ranges数组,并且在for循环中,应该使用这些Ranges一对一地绘制带有或不带有箭头的圆弧来填充整个圆环。 I can use drawing Arcs one by one to get whole circle having different segments in colour and thickness. 我可以一个接一个地绘制圆弧,以获得具有不同颜色和厚度段的整个圆。 Now question is how to add arrow heads to the Arcs? 现在的问题是如何在圆弧中添加箭头? Is it possible ? 可能吗 ?

在此处输入图片说明

First, just draw the whole circle, a simple path. 首先,只需画出整个圆,一条简单的路径即可。 Then, draw a somewhat more complex path for the first arrow and fill with red. 然后,为第一个箭头绘制一条稍微复杂的路径,并用红色填充。 Then draw the path for the second arrow and fill with black. 然后绘制第二个箭头的路径,并用黑色填充。 This should be pretty simple, the only trick is to do the math (ie trigonometry ) correctly to compute the control points for the paths. 这应该非常简单,唯一的技巧是正确地进行数学运算(即三角函数 )以计算路径的控制点。 If you do a lot of this kind of stuff, consider buying PaintCode, a Macintosh app that generates the code from your drawings. 如果您做很多这样的事情,请考虑购买PaintCode,这是一种Macintosh应用程序,可以从工程图中生成代码。

Here's a tutorial (which happens to include code for some some curved arrows): 这是一个教程(碰巧包括一些弯曲箭头的代码):

https://www.raywenderlich.com/38918/paintcode-tutorial-bezier-paths https://www.raywenderlich.com/38918/paintcode-tutorial-bezier-paths

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM