Cgcontextref
Cgcontextmovetopoint (context,150,50);//Start point of Arc
Cgcontextaddarctopoint (context,100,80,130,150,50);
is to say from (150,50) to (100,80) draw a line, and then from (100,80) to (130,150) draw a line, from the two lines (infinitely extended) and RADIUS 50 can determine an arc,
and
Cgcontextaddarc (context, 0, M_PI, 1);
Relatively simple, (100,100) is the coordinate of the center, 30 is the radius, (0,M_PI) is the starting angle and end angle, 1 is clockwise, 0 is counterclockwise
is to say from (150,50) to (100,80) draw a line, and then from (100,80) to (130,150) draw a line, from the two lines (infinitely extended) and RADIUS 50 can determine an arc
Uigraphicsgetcurrentcontext () will take the cgcontextref at the top of the stack,
The correct approach is to call Uigraphicsgetcurrentcontext () only in DrawRect,
Because before DrawRect, the system pushes a valid cgcontextref into the stack,
Unless you maintain a cgcontextref, you should not take cgcontextref elsewhere.
0 Cgcontextref context = uigraphicsgetcurrentcontext (); Setting the context
1 Cgcontextmovetopoint Start drawing lines
2 Cgcontextaddlinetopoint Draw Straight line
4 Cgcontextaddellipseinrect Draw an ellipse
4 Cgcontextsetlinecap Set line End shape
4 Cgcontextsetlinedash Draw Dashed line
4 Cgcontextaddrect Draw one side box
4 Cgcontextstrokerect Specify Rectangle
4 Cgcontextstrokerectwithwidth Specify the width of the rectangle Line
4 Cgcontextstrokelinesegments Some straight lines
5 Cgcontextaddarc Draw already curved front two stores for center between two stores for the starting radian the last data is 0 clockwise draw 1 counterclockwise
5 Cgcontextaddarctopoint (context,0,0, 2, 9, 40);//Draw two lines from point to the Brother 1 points, from the Brother 1 point to the Brother 2 points of the line cut inside the circle
6 Cgcontextsetshadowwithcolor Setting Shadows
7 Cgcontextsetrgbfillcolor This fill color
7 Cgcontextsetrgbstrokecolor Brush Color settings
7 Cgcontextsetfillcolorspace Color Space fill
7 Cgconextsetstrokecolorspace Color Space Brush settings
8 Cgcontextfillrect complements the current fill color rect
8 Cgcontextsetalaha Transparency
9 CGCONTEXTTRANSLATECTM changing the canvas position
Cgcontextsetlinewidth set the width of the line
Draw Multiple Lines Cgcontextaddrects
Cgcontextaddquadcurvetopoint Draw Curve
Cgcontextstrokepath Start Drawing Pictures
Cgcontextdrawpath Set Drawing Mode
Cgcontextclosepath Close the current line
CGCONTEXTTRANSLATECTM (context, 0, rect.size.height); CGCONTEXTSCALECTM (Context, 1.0,-1.0); Invert canvas
Cgcontextsetinterpolationquality background built-in color quality level
Cgimagecreatewithimageinrect take a small picture from the original image
17 writing of the string can be used in the drawing method of the NSString itself – (cgsize) Drawinrect: (cgrect) rect withfont: (Uifont *) font Linebreakmode: (uilinebreakmode) Linebreakmode alignment: (uitextalignment) alignment; just write it in.
18 The function of zooming in and out of the picture is a little slow.
Uigraphicsbeginimagecontext (newSize);
uiimage* newimage = Uigraphicsgetimagefromcurrentimagecontext ();
Uigraphicsendimagecontext ();
Cgcolorgetcomponents () returns the individual values of the color and the transparency available as a read-only const float to receive the array
Drawing Sheet cgimageref image=cgimageretain (img. Cgimage);
Cgcontextdrawimage (Context, CGRectMake (10.0, height–
100.0, 90.0, 90.0), image);
21 Implement the variable color Fill method cgcontextclip (context);
Cgcolorspaceref RGB = Cgcolorspacecreatedevicergb ();
CGFloat colors[] =
{
204.0/255.0, 224.0/255.0, 244.0/255.0, 1.00,
29.0/255.0, 156.0/255.0, 215.0/255.0, 1.00,
0.0/255.0, 50.0/255.0, 126.0/255.0, 1.00,
};
Cggradientref gradient = cggradientcreatewithcolorcomponents
(RGB, colors, NULL, sizeof (colors)/(sizeof (COLORS[0)));
Cgcolorspacerelease (RGB);
Cgcontextdrawlineargradient (Context, Gradient,cgpointmake
(0.0,0.0), Cgpointmake (0.0,self.frame.size.height),
Kcggradientdrawsbeforestartlocation);
22 Note: Once you have finished drawing, you must
First use Cgcontextstrokepath to stroke the line, that is, the shape
Then use Cgcontextfillpath to fill the color inside the shape.
When a path is populated, the paths inside the path are filled independently.
If the path is overlapping, determine whether a point is filled, there are two rules
1,nonzero Winding Number rule: non-0 rules, if a point is crossed from left to right, counter +1, from right to left, counter-1, and finally, if the result is 0, then no padding, if nonzero, then padding.
2,even-odd rule: Parity rules, if a point is crossed, then +1, and finally an odd number, then to be filled, even the number is not filled, and the direction is not related.
Function
Description
Cgcontexteofillpath
Populating the current path with parity rules
Cgcontextfillpath
Populating the current path with a non-0-wrap rule
Cgcontextfillrect
Fills the specified rectangle
Cgcontextfillrects
Fills a specified number of rectangles
Cgcontextfillellipseinrect
Fills the ellipse in the specified rectangle
Cgcontextdrawpath
Two parameters determine the fill rule, Kcgpathfill represents the rule with a non-0 number of rules, kcgpatheofill represents a parity rule, kcgpathfillstroke represents a fill, kcgpatheofillstroke represents a stroke, not a fill
Set when a color is covered on another color, two colors how to mix
The default method is
result = (Alpha * foreground) + (1–alpha) * background
Cgcontextsetblendmode: Set blend mode.
Cgcontextsavegstate: Save blend mode.
Cgcontextrestoregstate: Use this function to restore the blend mode before saving.
Cgcontextsetblendmode Mix Two colors
Simple usage of cgcontextref drawing line