Only override Drawrect:if perform custom drawing.
An empty implementation adversely affects performance during animation.
-(void) DrawRect: (cgrect) Rect {
uibezierpath *path = [uibezierpathbezierpath];
// start coordinates of the drawing
[path movetopoint:cgpointmake(+)];
// connect each coordinate in turn
[path addlinetopoint:cgpointmake(+)];
[path addlinetopoint:cgpointmake(+)];
[path addlinetopoint:cgpointmake(+)];
// closed
[PathClosepath];
// context
cgcontextref context =uigraphicsgetcurrentcontext();
// Save context State
cgcontextsavegstate(context);
// Draw outline of a graphic
[Pathstroke];
// move origin so that each coordinate moves in turn
CGCONTEXTTRANSLATECTM(context, ();
// Set color
uicolor *fillcolor = [uicolorgreencolor];
// Fill Color
[FillColorSetfill];
// Fill
[Pathfill];
// move Origin coordinates again
CGCONTEXTTRANSLATECTM(context, ();
// graphics rotation
CGCONTEXTROTATECTM(context,3.14/4);
FillColor = [uicolororangecolor];
[Pathfill];
//[path Stroke];
// Restore Context State ,
cgcontextrestoregstate(context);
cgcontextsavegstate(context);
CGCONTEXTTRANSLATECTM(context, ();
// graphics Shadows
Cgcontextsetshadow(context,cgsizemake(ten), 7 );
FillColor = [uicolorgraycolor];
[FillColorSetfill];
[Pathfill];
cgcontextrestoregstate(context); // Restore Context State
cgcontextsavegstate(context); // Save Context State
CGCONTEXTTRANSLATECTM(context,N.);
// define gradients
cggradientref mygradient;
// Declare color space
cgcolorspaceref colorspace =Cgcolorspacecreatedevicergb();
cgfloat components[8] = {1.0,0.0, 0.0, 1.0,
0.0, 0.0, 1.0, 1.0
};
cgfloat locations[2] = {0.2,0.8};
int num = 2;
Mygradient =cggradientcreatewithcolorcomponents(colorspace, components, locations, num);
[Pathaddclip ];
cgcontextdrawlineargradient(context, mygradient,cgpointmake(0, 0),cgpointmake(0),0);
cgcolorspacerelease(colorspace);
Cggradientrelease (mygradient);
cgcontextrestoregstate(context);
}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Draw graphics-Move, rotate, shadow, gradient