ios - drawRect - Draw Star -


i drawing annotations on view. approach using draw star below.

-(void)drawrect:(cgrect)rect {  cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetlinewidth(context, 2.0); cgfloat xcenter = rect.size.width / 2; cgfloat ycenter = rect.size.height / 2;  float width; if(rect.size.width > rect.size.height) {     width = rect.size.height; } else {     width = rect.size.width; }  double r = width / 2.0; float flip = -1.0;  double theta = 2.0 * m_pi * (2.0 / 5.0); // 144 degrees  cgcontextmovetopoint(context, xcenter, r*flip+ycenter);  (nsuinteger k=1; k<5; k++) {     float x = r * sin(k * theta);     float y = r * cos(k * theta);     cgcontextaddlinetopoint(context, x+xcenter, y*flip+ycenter); }  cgcontextsetstrokecolorwithcolor(context, self.color.cgcolor);  cgcontextclosepath(context); cgcontextstrokepath(context);  } 

i want have borders of star removing other inner lines there way achieve that? (apart using movetopoint , addline methods)

use code:

-(void)drawrect:(cgrect)rect {     int asize = 100.0;     float color[4] = { 0.0, 0.0, 1.0, 1.0 }; // blue     cgcolorref acolor = cgcolorcreate(cgcolorspacecreatedevicergb(), color);     cgcontextref context = uigraphicsgetcurrentcontext();     cgcontextsetlinewidth(context, asize);     cgfloat xcenter = 100.0;     cgfloat ycenter = 100.0;      float  w = 100.0;     double r = w / 2.0;     float flip = -1.0;      cgcontextsetfillcolorwithcolor(context, acolor);       cgcontextsetstrokecolorwithcolor(context, acolor);      double theta = 2.0 * m_pi * (2.0 / 5.0); // 144 degrees      cgcontextmovetopoint(context, xcenter, r*flip+ycenter);      (nsuinteger k=1; k<5; k++)      {         float x = r * sin(k * theta);         float y = r * cos(k * theta);         cgcontextaddlinetopoint(context, x+xcenter, y*flip+ycenter);     }      cgcontextclosepath(context);     cgcontextfillpath(context);     } 

this create 1 blue star


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -