- (void) DrawRect: (cgrect) rect{//Get ContextCgcontextref CTX =Uigraphicsgetcurrentcontext (); //save a copy of the purest graphics context//called once the method copies a context into the stackcgcontextsavegstate (CTX);//cgcontextsavegstate (CTX); //First line//saving drawing information with a graphical contextCgcontextmovetopoint (CTX, Max, -); Cgcontextaddlinetopoint (CTX, -, -); //set the state of the first lineCgcontextsetlinewidth (CTX,Ten); Cgcontextsetlinecap (CTX, Kcglinecapround); [[Uicolor Redcolor]Set]; //RenderingCgcontextstrokepath (CTX); //Restore the purest graphics context that you started to savecgcontextrestoregstate (CTX); //Second LineCgcontextmovetopoint (CTX, the, -); Cgcontextaddlinetopoint (CTX, the, Max); /*//emptying status Cgcontextsetlinewidth (CTX, 5); Cgcontextsetlinecap (CTX, Kcglinecapbutt); [[Uicolor Greencolor] set]; */ //Restore the purest graphics context that you started to savecgcontextrestoregstate (CTX); /*//3rd line Cgcontextmovetopoint (CTX, 200, 30); Cgcontextaddlinetopoint (CTX, 80, 150); */ //RenderingCgcontextstrokepath (CTX); }
IOS Graphics Context Stack