IOS Cgcontextref Drawing Common

Source: Internet
Author: User

Cgcontextref context = Uigraphicsgetcurrentcontext (); Setting the context

Draw a line

Cgcontextsetstrokecolorwithcolor (context, [Uicolor Redcolor]. Cgcolor);//Line Color

Cgcontextsetlinewidth (context, 5.0);//Line width

Cgcontextmovetopoint (Context, 20, 20); Start drawing line, X, y as the start point coordinates

Cgcontextaddlinetopoint (context, 300, 20);//Draw a straight line, X, y is the coordinate of the line end point

Cgcontextstrokepath (context); Start drawing lines

Draw a Bézier curve

The Bezier curve is drawn by moving a starting point, then through two control points, and a stop point, called the Cgcontextaddcurvetopoint () function.

Cgcontextsetlinewidth (context, 2.0);

Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);

Cgcontextmovetopoint (context, 10, 10);

Cgcontextaddcurvetopoint (context, 200, 50, 100, 400, 300, 400);

Cgcontextstrokepath (context);

Draw a continuous curve

Cgcontextsetlinewidth (context, 5.0);

Cgcontextsetstrokecolorwithcolor (context, [Uicolor Greencolor]. Cgcolor);

Cgcontextmovetopoint (context, 230, 150);//Start drawing lines, X, y is the coordinates of the start point

Cgcontextaddcurvetopoint (context, 310, 100, 300, 200, 220, 220);//Draw Three point curve

Cgcontextaddcurvetopoint (context, 290, 140, 280, 180, 240, 190);//Draw Three point curve

Cgcontextstrokepath (context);//Start drawing lines

Draw dashed lines

Cgcontextsetrgbstrokecolor (context, 0.1, 0.2, 0.3, 1);//Line Color

Float dasharray1[] = {3, 2};

Cgcontextsetlinedash (context, 0, dashArray1, 2);//dashed line, can refer to http://blog.csdn.net/zhangao0086/article/details/7234859

Cgcontextmovetopoint (Context, 5, 70);//Start drawing lines, X, y is the coordinates of the start point

Cgcontextaddlinetopoint (context, 310, 70);//Draw a straight line, X, y is the coordinate of the line end point

Cgcontextstrokepath (context);//Start drawing lines

Plot a virtual curve

Cgcontextsetrgbstrokecolor (context, 0.3, 0.2, 0.1, 1);//Line Color

Float dasharray2[] = {3, 2, 10};

Cgcontextsetlinedash (context, 0, dashArray2, 3);//Draw dashed lines

Cgcontextmovetopoint (Context, 5, 90);//Start drawing lines, X, y is the coordinates of the start point

Cgcontextaddcurvetopoint (context, 200, 50, 100, 400, 300, 400);

Cgcontextstrokepath (context);//Start drawing lines

Draw a continuous curve

Cgcontextsetlinewidth (context, 5.0);

Float dasharray3[] = {3, 2, 10, 20, 5};

Cgcontextsetlinedash (context, 0, dashArray3, 5);//Draw dashed lines

Cgcontextsetstrokecolorwithcolor (context, [Uicolor Greencolor]. Cgcolor);

Cgcontextmovetopoint (Context, 5, 400);//Start drawing lines, X, y is the coordinates of the start point

Cgcontextaddcurvetopoint (Context, 50, 200, 80, 300, 100, 220);//Draw Three point curve

Cgcontextaddquadcurvetopoint (context, 150, 100, 200, 200);//Draw Two point curve

Cgcontextaddcurvetopoint (context, 240, 400, 10, 50, 300, 300);//Draw Three point curve

Cgcontextstrokepath (context);//Start drawing lines

Draw a square shape without a border

Cgcontextsetrgbfillcolor (context, 0, 0.25, 0, 0.5); Fill Color of box

Cgcontextfillrect (Context, CGRectMake (5, 150, 100, 100)); Draw a Box

Draw an arc

Cgcontextsetrgbstrokecolor (context, 0.3, 0.4, 0.5, 1);//Line Color

Cgcontextaddarc (context, 0, 180* (m_pi/180), 0);

Cgcontextstrokepath (context);//Start drawing lines

Draw a square border

Cgcontextref CONTEXT5 = Uigraphicsgetcurrentcontext (); Setting the context

Cgcontextsetlinewidth (CONTEXT5, 3.0);

Cgcontextsetrgbstrokecolor (CONTEXT5, 0.8, 0.1, 0.8, 1);

Cgcontextstrokerect (CONTEXT5, CGRectMake (5, 5, 300, 400));//Draw a square border, parameter 2: square coordinates.

Draw an Ellipse

CGRect arect= CGRectMake (80, 80, 160, 100);

Cgcontextsetrgbstrokecolor (context, 0.6, 0.9, 0, 1.0);

Cgcontextsetlinewidth (context, 3.0);

Cgcontextaddellipseinrect (context, arect); Ellipse, Parameter 2: the coordinates of the ellipse.

Cgcontextdrawpath (context, kcgpathstroke);

Draw a solid circle

Cgcontextfillellipseinrect (Context, CGRectMake (95, 195, 200.0, 100));//Draw a solid circle, parameter 2: round coordinates. Can be an ellipse

Draw a Diamond

Cgcontextsetlinewidth (context, 2.0);

Cgcontextsetstrokecolorwithcolor (context, [Uicolor Bluecolor]. Cgcolor);

Cgcontextmovetopoint (context, 100, 100);

Cgcontextaddlinetopoint (context, 150, 150);

Cgcontextaddlinetopoint (context, 100, 200);

Cgcontextaddlinetopoint (context, 50, 150);

Cgcontextaddlinetopoint (context, 100, 100);

Cgcontextstrokepath (context);

Fills a path:

Cgcontextmovetopoint (context, 100, 100);

Cgcontextaddlinetopoint (context, 150, 150);

Cgcontextaddlinetopoint (context, 100, 200);

Cgcontextaddlinetopoint (context, 50, 150);

Cgcontextaddlinetopoint (context, 100, 100);

Cgcontextsetfillcolorwithcolor (context, [Uicolor Redcolor]. Cgcolor);

Cgcontextfillpath (context);

IOS Cgcontextref Drawing Common

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.