Introduction to Quart Plotting Method for IOS development

Source: Internet
Author: User

When we first came into contact with Quertz 2D, it was important that the drawing was performed in the context of the drawing. Each view has an associated context.

Therefore, if you draw a graph in a view, we need to retrieve the current context.

CGContextRef ctx =
UIGraphicsGetCurrentContext ();

// Retrieve the current context. Each view of the drawing has an associated context, and then pass the context to the core graphics drawing function to draw

CGContextSetLineWidth (ctx, 3.0); // you can specify 2 pixels for a straight line;

CGContextSetStrokeColorWithColor (ctx, [UIColor greenColor]. CGColor); // specify that the stroke color is green;

Note that there are two different color settings in the drawing operation:

The stroke color is used to draw a straight line or a Shape Contour (such as a circular square)

Fill color is used to fill the shape (inside)

CGContextMoveToPoint (ctx, 0.0f, 0.0f); // the starting point of a straight line

CGContextAddLineToPoint (ctx,
100,100); // The end of a straight line. When this function is called, The Invisible stroke is moved to a new position, but no content is drawn.

CGContextStrokePath (ctx); // This function draws a straight line.

 
 
  1. Cgcontextsetrgbfillcolor/cgcontextsetfillcolorwithcolor // fill color
  2. Cgcontextsetrgbstrokecolor/cgcontextsetstrokecolorwithcolor // stroke color
  3. Cgcontextsetlinewidth // line width



Another important property of drawing is color.

In common development applications, we usually use UIColor to set the color. However, in Quertz 2D, we cannot directly call the UIColor object, but UIColor contains the CGColor attribute.

@ Property (nonatomic,
Readonly) cgcolorref cgcolor; so we can use [uicolor bluecolor]. cgcolor when setting the color.

The above briefly introduces the line and CGColor, but what if we need to use Core Graphics to operate CGImage. At this time, we need to specify a CGPoint to determine the upper left corner of the image or specify a CGRect to frame the image. It is appropriate to adjust the image size period as needed.

CGPoint drawPoint = CGPointMake (100366f, 11.0f );

[Image drawAtPoint: drawPoint];


Draw shape:

Draw an elliptical shape: CGRect rect = CGRectMake (0, 0,100,100 );

CGContextAddEllipseInRect (ctx, rect );

CGContextDrawPath (ctx,
KCGPathFillStroke );


CGContextAddRect (CGContextRef c,
CGRect rect)

CGContextAddRects (CGContextRef c,
Const cgrect rects [], size_t count];

CGContextAddLines (CGContextRef c,
Const CGPoint points [], size_t count];

CGContextAddEllipseInRect (CGContextRef context,
CGRect rect)

Cgcontextaddarc

CGContextAddArcToPoint

Cgcontextaddpath (cgcontextref context,
Cgpathref path)


Related Article

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.