ios - Core Graphics - Shadow not seen -


i wrote simple drawrect intention of drawing circle, drop shadow , fill blue. have achieved drawing circle , filling in blue shadow not in effect. instead of fill if stroke circle, see shadow inside circle , during fill drawn on fill colour

rect drawrect has dimension [[custombutton alloc]initwithframe:cgrectmake(0, 0, 50, 50)];

@implementation custombutton  - (id)initwithframe:(cgrect)frame { self = [super initwithframe:frame]; if (self) {     [self setbackgroundcolor:[uicolor clearcolor]]; } return self; }  - (void)drawrect:(cgrect)rect { cgcontextref context = uigraphicsgetcurrentcontext(); cgcolorref colorref = [[uicolor bluecolor] cgcolor]; cgcontextsetstrokecolorwithcolor(context, colorref); cgcontextsetfillcolorwithcolor(context, [[uicolor bluecolor] cgcolor]);   cgrect buttonrect = cgrectinset(rect, 3, 3);  cgpoint centerpoint = cgpointmake(cgrectgetmidx(buttonrect  ),     cgrectgetmidy(buttonrect)); cgfloat radius = cgrectgetwidth(buttonrect) / 2;  cgcontextsavegstate(context); cgcontextsetshadow(context, cgsizemake(15.0, 20.0), 1.0); cgcontextaddarc(context, centerpoint.x, centerpoint.y, radius, 0, 2*m_pi, 1); cgcontextclip(context); cgcontextfillrect(context, buttonrect); cgcontextrestoregstate(context);   cgcolorrelease(colorref);  }  @end 

thank you

try this:

- (void)drawrect:(cgrect)rect {     cgcontextref context = uigraphicsgetcurrentcontext();     cgcolorref colorref = [[uicolor bluecolor] cgcolor];     cgcontextsetstrokecolorwithcolor(context, colorref);     cgcontextsetfillcolorwithcolor(context, [[uicolor bluecolor] cgcolor]);       cgrect buttonrect = cgrectinset(rect, 3, 3);      cgpoint centerpoint = cgpointmake(cgrectgetmidx(buttonrect  ),     cgrectgetmidy(buttonrect));     cgfloat radius = cgrectgetwidth(buttonrect) / 2;      cgcontextsavegstate(context);     cgcontextsetshadow(context, cgsizemake(2.0, 2.0), 2.0);     cgcontextaddarc(context, centerpoint.x, centerpoint.y, radius, 0, 2*m_pi, 1);     //cgcontextclip(context);     cgcontextfillpath(context);     cgcontextrestoregstate(context);       cgcolorrelease(colorref); } 

your shadow rectangular , why not seen under circle. changed call cgcontextfillrect cgcontextfillpath, path create using cgcontextaddarc.

is going for?

edit

you can find project here: https://bitbucket.org/reydan/so_circleshadow


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -