Functions are required to draw dotted lines:
 
Cgcontextsetlinedash
 
This function requires four parameters:
 
 
 
 - Context-Needless to say
- Phase-Later
- Lengths-Specify how the dotted line is drawn alternately. For details, refer to the example.
- Count-Lengths array Length
 
 - Cgcontextref context = uigraphicsgetcurrentcontext ();
- Cgcontextbeginpath (context );
- Cgcontextsetlinewidth (context, 2.0 );
- Cgcontextsetstrokecolorwithcolor (context, [uicolorwhitecolor]. cgcolor );
- Float lengths [] = {10 };
- Cgcontextsetlinedash (context, 0, lengths, 2 );
- Cgcontextmovetopoint (context, 10.0, 20.0 );
- Cgcontextaddlinetopoint (context, 310.0, 20.0 );
- Cgcontextstrokepath (context );
- Cgcontextclosepath (context );
The lengths value {10, 10} indicates that 10 points are first drawn, and then 10 points are skipped,
 
 
If the value of lengths is changed to {10, 20, 10}, 10 points are drawn first, 20 points are skipped, 10 points are drawn, and 10 points are skipped, draw 20 more points, so repeatedly,
 
 
Note that the value of count is equal to the length of the lengths array.
 
The phase parameter indicates how many vertices are skipped when the first dotted line is drawn. For example:
 
 
 
 
 - Float lengths [] = {10, 5 };
- Cgcontextsetlinedash (context, 0, lengths, 2 );
- Cgcontextmovetopoint (context, 0.0, 20.0 );
- Cgcontextaddlinetopoint (context, 310.0, 20.0 );
- Cgcontextstrokepath (context );
- Cgcontextsetlinedash (context, 5, lengths, 2 );
- Cgcontextmovetopoint (context, 0.0, 40.0 );
- Cgcontextaddlinetopoint (context, 310.0, 40.0 );
- Cgcontextstrokepath (context );
- Cgcontextsetlinedash (context, 8, lengths, 2 );
- Cgcontextmovetopoint (context, 0.0, 60.0 );
- Cgcontextaddlinetopoint (context, 310.0, 60 .);
- Cgcontextstrokepath (context );
Display:
 
 
 
Since the lengths value is {10, 5}, the first line is to draw 10, skip 5, and draw repeatedly.
 
If the phase value of the second line is 5, first draw [10 minus 5], then skip 5, draw 10, and draw again.
 
The third is also true. Draw 2 first and then skip 5.