PATHVIEW.M//Qauze////Created by Apple on 16/6/2. copyright©2016 the year of Li Chongyang.
All rights reserved. #import "PathView.h" @implementation Pathview-(Instancetype) initWithFrame: (CGRect) Frame {if (self = [super] in
Itwithframe:frame]) {self.backgroundcolor = [uicolor Bluecolor];
} return self;
}-(void) DrawRect: (cgrect) rect {[Self cgpath];
[Self cgcontext];
[Self Bézier];
[Self drawround];
}/* * One: Cgpath **/-(void) Cgpath {cgcontextref ref = Uigraphicsgetcurrentcontext ();
Cgmutablepathref pathref = cgpathcreatemutable ();
1. Set the starting point Cgpathmovetopoint (Pathref, Nil, 5, 5);
2. Join line Cgpathaddlinetopoint (Pathref, Nil, 50, 50);
3. Place path into Contextref Cgcontextaddpath (ref, PATHREF);
Cgpathrelease (PATHREF);
[[Uicolor Redcolor]setstroke]; Cgcontextsetstrokecolorwithcolor (ref, [Uicolor Redcolor].
Cgcolor); /* * This sentence must be added or not to start drawing * This is the beginning of drawing Cgpath path **/CgcontexTstrokepath (ref);
}/* II: Draw directly with Cgcontext **/-(void) Cgcontext {cgcontextref ref = Uigraphicsgetcurrentcontext ();
Cgcontextmovetopoint (ref, 50, 50);
Cgcontextaddlinetopoint (ref, 100, 100);
Cgcontextaddlinetopoint (ref, 10, 60);
Cgcontextsetlinewidth (ref, 5);
Cgcontextsetlinecap (ref, Kcglinecapround);
Cgcontextsetlinejoin (ref, Kcglinejoinbevel);
[[Uicolor Yellowcolor]setfill];
[[Uicolor Cyancolor]setstroke]; /* * 3 ways to draw path * 1.CGCONTEXTFILLPATH (ref); Draw Fill * 2.CGContextStrokePath (ref); Draw strokes * 3.CGContextDrawPath (ref, Kcgpathfillstroke);
Draw fill and Stroke **/cgcontextdrawpath (ref, Kcgpathfillstroke);
}/* Bézier curve **/-(void) Bézier {uibezierpath * path = [Uibezierpath Bezierpath];
[Path Movetopoint:cgpointmake (100,100)];
[Path Addlinetopoint:cgpointmake (200, 100)];
[Path Addlinetopoint:cgpointmake (150, 200)];
[Path Setlinecapstyle:kcglinecapround]; [Path Setlinejoinstyle:kcglinejoinbeVEL];
[Path Setlinewidth:5];
[[Uicolor Redcolor]setfill];
[[Uicolor Yellowcolor]setstroke];
[Path stroke];
[Path fill];
[Path Closepath];
}/* Bezier curve Draw circle, ellipse, Sector **/-(void) Drawround {//Draw circle Uibezierpath * Path = [Uibezierpath Bezierpath];
[Path Addarcwithcenter:cgpointmake (radius:50) startangle:0 endangle:m_pi*1.5 Clockwise:yes];
[Path setlinewidth:10];
[[Uicolor Yellowcolor]setstroke];
[Path stroke];
Draw Ellipse Uibezierpath * path1 = [Uibezierpath bezierpathwithovalinrect:cgrectmake (0, 0, 100, 200)];
[Path1 Setlinewidth:5];
[path1 stroke];
} @end