Learn iOS Development UI Chapter--quartz2d Basic Drawing

Source: Internet
Author: User

quartz2d code steps for drawing

1. Get the graphics context
Cgcontextref CTX = Uigraphicsgetcurrentcontext ();

2. Stitching the path (the following code is to make a line)
Cgcontextmovetopoint (CTX, 10, 10);
Cgcontextaddlinetopoint (CTX, 100, 100);

3. Draw the Path
Cgcontextstrokepath (CTX); Cgcontextfillpath (CTX);

Common Stitching path function

1. Create a new starting point
void Cgcontextmovetopoint (Cgcontextref C, CGFloat x, cgfloat y)

2. Add a new segment to a point
void Cgcontextaddlinetopoint (Cgcontextref C, CGFloat x, cgfloat y)

3. Add a rectangle
void Cgcontextaddrect (Cgcontextref C, CGRect rect)

4. Add an ellipse
void Cgcontextaddellipseinrect (Cgcontextref context, CGRect rect)

5. Add an arc
void Cgcontextaddarc (Cgcontextref C, CGFloat x, CGFloat y,
CGFloat radius, cgfloat startangle, cgfloat endangle, int clockwise)

Common Drawing Path functions

1.Mode parameters determine the pattern to be drawn
void Cgcontextdrawpath (cgcontextref C, Cgpathdrawingmode mode)

2. Draw a hollow path
void Cgcontextstrokepath (Cgcontextref c)

3. Draw a solid path
void Cgcontextfillpath (Cgcontextref c)

Tip: Functions that are usually started with Cgcontextdraw, Cgcontextstroke, and Cgcontextfill are used to draw the path

Operation of the graphics context stack

1. Save the current context copy to the top of the stack (the stack is called the "graphics context stack")
void Cgcontextsavegstate (Cgcontextref c)

2. Replace the current context
void Cgcontextrestoregstate (Cgcontextref c)

Using methods such as CGCONTEXTSCLATECTM, be sure to call before assigning properties

When using Cgcontextclip, be sure to call before drawing

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.