ios - Different behaviours for different colors in drawRect: -
this question has answer here:
i puzzled way following code works. expected produce black disk surrounded colored circle. works fine colors (as explained in comments), not others. can explain misterious behaviour?
- (void)drawrect:(cgrect)rect { cgrect rectangle; cgfloat shiftval=2.0,linewidth=3.0; rectangle.origin=cgpointmake(shiftval, shiftval); rectangle.size=self.frame.size; rectangle.size.width-=shiftval*2; rectangle.size.height-=shiftval*2; cgcontextref context = uigraphicsgetcurrentcontext(); cgcontextsetrgbfillcolor(context, 0.0, 0.0, 0.0, 1.0); cgcontextfillellipseinrect(context, rectangle); cgcontextsetlinewidth(context, linewidth); const cgfloat *components = cgcolorgetcomponents([uicolor greencolor].cgcolor); // works expected. //const cgfloat *components = cgcolorgetcomponents([uicolor darkgraycolor].cgcolor); // no surrounding circle (instead of darkgray). //const cgfloat *components = cgcolorgetcomponents([uicolor lightgraycolor].cgcolor); // produces greenish circle (instead of lightgray) // draw outer circle: cgcontextsetrgbstrokecolor(context, components[0], components[1], components[2], components[3]); cgcontextstrokeellipseinrect(context, rectangle); }
similar this answer guessing darkgraycolor
, lightgraycolor
both represent gray-sacle values rather tan rgba-values. , therefore dont have 4 comoponents 2.
you might want / have use different approach of setting color:
cgcontextsetstrokecolorwithcolor(context, [uicolor darkgraycolor].cgcolor);
Comments
Post a Comment