Some simple applications for animations. Here is an example of drawing a straight line.
The method of drawing is in DrawRect
Executed, the DrawRect method is similar to Cellforrowatindexpath, and can be executed directly by the system without calling in initWithFrame or Viewdidload.
Below, draw an irregular line, the necessary code
1-(void) DrawRect: (cgrect) rect{2Self.backgroundcolor =[Uicolor Lightgraycolor];3 //Gets the context of the processing4Cgcontextref context =Uigraphicsgetcurrentcontext ();5 //set the color of a line6 Cgcontextsetstrokecolorwithcolor (context, [Uicolor Redcolor]. Cgcolor);7 //The starting point is set to (0,0): Note that this is the relative coordinate in the corresponding area of the context,8Cgcontextmovetopoint (Context,0,0);9 //set the next coordinate pointTenCgcontextaddlinetopoint (Context, -, -); One //set the next coordinate point ACgcontextaddlinetopoint (Context,0, Max); - //set the next coordinate point -Cgcontextaddlinetopoint (Context, -, the); the //set the next coordinate point -Cgcontextaddlinetopoint (Context,Ten, -); - //connect the coordinate points defined above, that is, start drawing - Cgcontextstrokepath (context); +}
The following code is non-essential. The color settings for a line can also be considered unnecessary
// Set Line Style Cgcontextsetlinecap (context, kcglinecapsquare); // Set the line thickness width, default to 1.0 1.0 ); // start a start path Cgcontextbeginpath (context);
The effect is as follows
If you want to draw a histogram, you just need to use the cgcontextsetlinewidth to draw the line thick point on it, if the line chart also the same.
Simple usage of drawing lines using DrawRect