1. What is quartz2d
? Quartz2d is a two-dimensional drawing engine that supports both iOS and Mac systems? Quartz 2D can do the workdrawing: lines \ triangles \ rectangles \ Circles \ Arcs, etc.Draw Textdraw \ Generate picture (image)read \ Generate PDF\ crop a pictureCustomizing UI Controls
2. Custom View
Graphics context
? Graphics context: Is a cgcontextref type of data
What is the role of the graphics context?Save drawing information, drawing statusdecide where to draw the output target (where to draw?) )
(The output target can be a PDF file, a bitmap or a display window)
DrawRect: Context acquired in
When you get the context in the DrawRect: method, you can draw something to the view
? There is a layer property inside the view, DrawRect: A layer Graphics Context is obtained in the method, so the drawing is actually drawn to the view layer.
? View is able to show things entirely because of its inner layer
quartz2d code steps for drawing
Get the graphics context cgcontextref CTX = Uigraphicsgetcurrentcontext (); Stitching path (the code below is a line segment) Cgcontextmovetopoint (CTX, 10, 10); Cgcontextaddlinetopoint (CTX, 100, 100); Draw path Cgcontextstrokepath (CTX); Cgcontextfillpath (CTX);
Common stitching path function
New starting point void Cgcontextmovetopoint (Cgcontextref C, CGFloat x, cgfloat y) adds a new segment to a point void Cgcontextaddlinetopoint ( Cgcontextref c, CGFloat x, cgfloat y) add a rectangle void Cgcontextaddrect (cgcontextref C, CGRect rect) to add an ellipse void Cgcontextaddellipseinrect (cgcontextref context, CGRect rect) adds an arc void Cgcontextaddarc (Cgcontextref C, CGFloat X, CGFloat y, cgfloat radius, cgfloat startangle, cgfloat endangle, int clockwise)
common drawing path Functions
The mode parameter determines the drawn pattern void Cgcontextdrawpath (cgcontextref C, Cgpathdrawingmode mode) to draw the Hollow path void Cgcontextstrokepath ( Cgcontextref c) Draw a solid path void Cgcontextfillpath (Cgcontextref c) Hint: functions normally beginning with Cgcontextdraw, Cgcontextstroke, Cgcontextfill That are used to draw the path.
operation of the graphics context stack
A copy of the current context is saved to the top of the stack (the stack is called the "graphics context stack") void Cgcontextsavegstate (Cgcontextref c) Stacks the context of the top of the stack, replacing the current context void Cgcontextrestoregstate (Cgcontextref c)
Matrix Operations
With the matrix operation, all paths drawn into the context can be changed with the zoom void Cgcontextscalectm (Cgcontextref C, cgfloat SX, cgfloat sy) rotating void Cgcontextrotatectm ( Cgcontextref c, cgfloat angle) translation void Cgcontexttranslatectm (Cgcontextref c, CGFloat tx, cgfloat ty)
Image Watermark
Opens a bitmap-based graphics context void uigraphicsbeginimagecontextwithoptions (cgsize size, BOOL opaque, cgfloat scale) Get Picture from context (UIImage) uiimage* uigraphicsgetimagefromcurrentimagecontext (); End bitmap-based graphics context void Uigraphicsendimagecontext ();
Picture Clipping
void Cgcontextclip (cgcontextref c) Crops the path currently drawn up or down (which cannot be displayed beyond the clipping area)
Screen
-(void) Renderincontext: (cgcontextref) ctx; Renderincontext: Method to invoke the layer of a view
Quartz 2D Official document download
15.ios of quartz2d