Use quartz 2D to draw dotted lines

Source: Internet
Author: User

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

  1. Cgcontextref context = uigraphicsgetcurrentcontext ();
  2. Cgcontextbeginpath (context );
  3. Cgcontextsetlinewidth (context, 2.0 );
  4. Cgcontextsetstrokecolorwithcolor (context, [uicolorwhitecolor]. cgcolor );
  5. Float lengths [] = {10 };
  6. Cgcontextsetlinedash (context, 0, lengths, 2 );
  7. Cgcontextmovetopoint (context, 10.0, 20.0 );
  8. Cgcontextaddlinetopoint (context, 310.0, 20.0 );
  9. Cgcontextstrokepath (context );
  10. 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:

  1. Float lengths [] = {10, 5 };
  2. Cgcontextsetlinedash (context, 0, lengths, 2 );
  3. Cgcontextmovetopoint (context, 0.0, 20.0 );
  4. Cgcontextaddlinetopoint (context, 310.0, 20.0 );
  5. Cgcontextstrokepath (context );
  6. Cgcontextsetlinedash (context, 5, lengths, 2 );
  7. Cgcontextmovetopoint (context, 0.0, 40.0 );
  8. Cgcontextaddlinetopoint (context, 310.0, 40.0 );
  9. Cgcontextstrokepath (context );
  10. Cgcontextsetlinedash (context, 8, lengths, 2 );
  11. Cgcontextmovetopoint (context, 0.0, 60.0 );
  12. Cgcontextaddlinetopoint (context, 310.0, 60 .);
  13. 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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.