简体   繁体   中英

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. So, I have attributedstring and some ranges of the string have different colors. 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. 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.

Here's a tutorial (which happens to include code for some some curved arrows):

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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