1. Three ways to draw arrows
Drawing code//cgcontextref con = uigraphicsgetcurrentcontext ();////draw a black (by default) vertical line,the Shaft of the arrow shaft//Cgcontextmovetopoint (con, +);//Cgcontextaddlinetopoint (con, +);//Cgconte Xtsetlinewidth (con);//Cgcontextstrokepath (con);////draw a red triangle,the point of the arrow//Cgcontextse Tfillcolorwithcolor (Con, [[Uicolor Redcolor] cgcolor]);//Cgcontextmovetopoint (con, +);//Cgcontextaddlinetopoi NT (con, 0);//Cgcontextaddlinetopoint (con, +);//Cgcontextfillpath (con);////snip a triangle out of th e shaft by drawing in clear blend mode//cgcontextmovetopoint (Con, n, d);//Cgcontextmovetopoint (Con, 100, 90);// Cgcontextmovetopoint (Con, max),//Cgcontextsetblendmode (con, kcgblendmodeclear);//Cgcontextsetalpha (Con, 1 .0);//Cgcontextfillpath (con); When you need to obtain Cgpath, you can use uibezierpath//uibezierpath *p = [Uibezierpath bezierpath];////[P moveToPoint:Cgpointmake (+)];//[P addlinetopoint:cgpointmake (+)];//[P setlinewidth:20];//[P stroke];//[UI Color Redcolor] set];//[P removeallpoints];//[P Movetopoint:cgpointmake (+)];//[P ADDLINETOPOINT:CGPOINTMA Ke (0)];//[P addlinetopoint:cgpointmake (+)];//[P fill];////[P removeallpoints];//[P Movetopo Int:cgpointmake (101)];//[P addlinetopoint:cgpointmake (+)];//[P Addlinetopoint:cgpointmake (110, 101)];// [P fillwithblendmode:kcgblendmodeclear alpha:1.0]; Clipping cgcontextref con = uigraphicsgetcurrentcontext (); Punch triangular hole in the context clipping region cgcontextmovetopoint (Con, 90, 100); Cgcontextaddlinetopoint (Con, 100, 90); Cgcontextaddlinetopoint (Con, 110, 100); Cgcontextclosepath (con); Cgcontextaddrect (Con, cgcontextgetclipboundingbox (con)); Cgcontexteoclip (con); Draw the vertical line cgcontextmovetopoint (con, 100, 100); Cgcontextaddlinetopoint (CON, 100, 19); Cgcontextsetlinewidth (Con, 20); Cgcontextstrokepath (con); Draw the red triangle.the point of the arrow cgcontextsetfillcolorwithcolor (Con, [[Uicolor Redcolor] cgcolor]); Cgcontextmovetopoint (Con, 80, 25); Cgcontextaddlinetopoint (Con, 100, 0); Cgcontextaddlinetopoint (Con, 120, 25); Cgcontextfillpath (con);
Effect:
Cgcontextref con = Uigraphicsgetcurrentcontext (); [Self arrowimage] drawatpoint:cgpointmake (0, 0)]; for (int i=0; i<3; i++) {CGCONTEXTTRANSLATECTM (con, 20, 100); Cgcontextrotatectm (Con, 30*m_pi/180); Cgcontexttranslatectm (Con,-20,-100); [Self arrowimage] drawatpoint:cgpointmake (0, 0)]; }//}-(UIImage *) arrowimage{uigraphicsbeginimagecontextwithoptions (Cgsizemake (+), NO, 0.0); Cgcontextref con = Uigraphicsgetcurrentcontext (); Punch triangular hole in the context clipping region cgcontextmovetopoint (Con, 10, 100); Cgcontextaddlinetopoint (Con, 20, 90); Cgcontextaddlinetopoint (Con, 30, 100); Cgcontextclosepath (con); Cgcontextaddrect (Con, cgcontextgetclipboundingbox (con)); Cgcontexteoclip (con); Draw the vertical line cgcontextmovetopoint (con, 20, 100); Cgcontextaddlinetopoint (Con, 20, 19); Cgcontextsetlinewidth (Con, 20); Cgcontextstrokepath (con); Draw the red triangle.the point ofThe arrow cgcontextsetfillcolorwithcolor (Con, [[Uicolor Redcolor] cgcolor]); Cgcontextmovetopoint (Con, 0, 25); Cgcontextaddlinetopoint (Con, 20, 0); Cgcontextaddlinetopoint (Con, 40, 25); Cgcontextfillpath (con); UIImage *im = Uigraphicsgetimagefromcurrentimagecontext (); Uigraphicsendimagecontext (); return im;}
When I'm not drawing in (0,0) There's a problem, as if it was caused by a coordinate system change.
Cgcontextref con = Uigraphicsgetcurrentcontext (); [Self arrowimage] drawatpoint:cgpointmake (); for (int i=0; i<12; i++) { cgcontexttranslatectm (con, +); Cgcontextrotatectm (Con, 30*m_pi/180); Cgcontexttranslatectm (Con, -20, -100); [Self arrowimage] drawatpoint:cgpointmake (); }
Have not found the reason, have to know the children's shoes, welcome to inform, communicate together
Core Graphics Learning Note Image Drawing (ii)