1 #import<UIKit/UIKit.h>2 3 @interfaceNjlineview:uiview4 @end5 6 7 #import "NJLineView.h"8 9 @implementationNjlineviewTen One //the DrawRect method is called when the custom view is first displayed A- (void) DrawRect: (cgrect) Rect - { - //1. Get the graphical context associated with the current view (because the graphics context determines the output target to be drawn)/ the - //if the Uigraphicsgetcurrentcontext method is called in the DrawRect method , the context of the layer is obtained. -Cgcontextref CTX =Uigraphicsgetcurrentcontext (); - + //2. Drawing (drawing lines), saving drawing information - //set the starting point +Cgcontextmovetopoint (CTX,Ten, -); A //Set End point atCgcontextaddlinetopoint (CTX, -, -); - - //Set Drawing status - //Set Line Color red -Cgcontextsetrgbstrokecolor (CTX,1.0,0,0,1.0); - //Set line width inCgcontextsetlinewidth (CTX,Ten); - //styling the start and end points of a line to Cgcontextsetlinecap (CTX, kcglinecapround); + //style to set the corners of a line - Cgcontextsetlinejoin (CTX, kcglinejoinround); the //draw a hollow line * Cgcontextstrokepath (CTX); $ Panax Notoginseng /*------------------Gorgeous split-line---------------------*/ - the //Reset the start point of the second line +Cgcontextmovetopoint (CTX, Max, $); A //sets the end of the second line (automatically the end of the previous line as the starting point) theCgcontextaddlinetopoint (CTX, -, -); + //set the color of the second line green - //[[Uicolor Greencolor] set]; $Cgcontextsetrgbstrokecolor (CTX,0,1.0,0,1.0); $ - //drawing Graphics (rendering graphics to view) - //draw a hollow line the Cgcontextstrokepath (CTX); - Wuyi } the - @end
Line of basic graphics for iOS drawing