IOS using DrawRect: Draw dashed ellipse
1: First if you want to use DrawRect drawing
To import the Coregraphics.framework framework
Then create a custom view, that is myview inherit UIView;
2: Rewrite
-(void) DrawRect: (cgrect) rect
Method
3: Add the following code
- (void) DrawRect: (cgrect) rect{cgcontextref context=Uigraphicsgetcurrentcontext (); CGFloat lengths[]= {5,5,5,5}; CGRect Arect= CGRectMake ( -,1, self.bounds.size.width- -*2, self.bounds.size.height-4); Cgcontextsetrgbstrokecolor (Context,1.0,1.0,1.0,1.0); Cgcontextsetlinedash (Context,0, lengths,4); Cgcontextsetlinewidth (Context,3.0); Cgcontextaddellipseinrect (context, arect); //EllipseCgcontextdrawpath (context, kcgpathstroke); }
Main functions
Cgcontextsetrgbstrokecolor(context, R, G, B, 1.0); Set the color of the graphic line;
Cgcontextsetlinedash (context, 0, lengths, 4); Set lines as dashed lines;
Cgcontextsetlinewidth(context, 3.0); Set the line width;
Cgcontextaddellipseinrect(context, arect); //Draw Ellipse
Cgcontextdrawpath(context, Kcgpathstroke);
Reference: http://blog.csdn.net/zhangao0086/article/details/7234859
http://blog.csdn.net/zhibudefeng/article/details/8463268