The UIView-(void) DrawRect: (cgrect) Rect function can be re-painted on the view with the sub-class.
Re-painting can be done through the core graphics and Uibezierpath.
1. Painting with the core graphics function
The first step is to get the current drawing context through the Uigraphicsgetcurrentcontex () function.
Then set the starting point, increase the line to a point,,,, close, for example:
//gets the current paint contextCgcontextref context=Uigraphicsgetcurrentcontext (); //sets the starting point of the painting, and if the part to be drawn exceeds the bounding frame of the current drawing context, the excess is clippedCgcontextmovetopoint (Context,- -, -Ten); //Add a line to point 100,200Cgcontextaddlinetopoint (Context, -, $); Cgcontextaddlinetopoint (Context,0, $); //closing line to beginningCgcontextclosepath (context); //here is the stroke, here can not be missing, otherwise the painting does not work, the previous operation looks more like the following to prepare for the drawing, only the following step is executed to succeedCgcontextstrokepath (context);
:
2.nsstirng,uiimage, you can draw directly in the current context
UIImage * Card = [UIImage imagenamed:@ "cardback"]; [Card Drawatpoint:cgpointmake (-ten,-ten)]; [@ "Hello cgcontext" drawatpoint:cgpointmake (ten) Withattributes:nil];
:
3.UIBezierPath painting
Uibezierpath * Path = [[Uibezierpath alloc] init]; [Path Movetopoint:cgpointmake (ten)]; [Path Addlinetopoint:cgpointmake]; [Path Addlinetopoint:cgpointmake]; [Path Closepath]; // here is the stroke, here can not be missing, otherwise the painting does not work, the previous operation looks more like the following to prepare for the drawing, only the following step is executed to succeed [Path stroke];
Uibezierpath and the core graphics function are drawn almost, except that they can be drawn directly without the current context, and are generally drawn using Uibezierpath.
The core graphics function is only used when Uibezierpath cannot be implemented.
:
iOS uses core graphics and Uibezierpath painting