ios - What is wrong with my CGContextclip. -


i beginner core garphics , try around understanding of cgcontextclip. doing simple program custom uibutton drawrect below

rect dimension passed drawrect method custombutton *button = [[custombutton alloc]initwithframe:cgrectmake(0, 0, 100, 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]); cgcontextsetlinewidth(context, 3.0f);  cgcontextaddrect(context, rect); cgcontextstrokerect(context, rect); //cgcontextfillrect(context, rect);  cgcontextsavegstate(context); cgcontextsetstrokecolorwithcolor(context, [[uicolor redcolor] cgcolor]); cgcontextsetfillcolorwithcolor(context, [[uicolor redcolor]cgcolor]);  cgmutablepathref rectpath = cgpathcreatemutable();  cgpathmovetopoint(rectpath, null, cgrectgetminx(rect), cgrectgetmidy(rect)); cgpathaddlinetopoint(rectpath, null, cgrectgetmaxx(rect), cgrectgetmidy(rect)); cgpathaddlinetopoint(rectpath, null, cgrectgetmaxx(rect), cgrectgetmaxy(rect)); cgpathaddlinetopoint(rectpath, null, cgrectgetminx(rect), cgrectgetmaxy(rect)); cgpathclosesubpath(rectpath);  cgcontextaddpath(context, rectpath); cgcontextclip(context); cgcontextstrokepath(context); //cgcontextfillpath(context); cgcontextrestoregstate(context);  cgcolorrelease(colorref); }  @end 

i expecting full rect dimension (0,0,100,50) colored in blue , half rect inside red coloured. getting blue colored rect red colored rect not visible in context.

i have gone through solution here , @ blogs faulty eyes code looks simple , fine. wrong clipping.

thank time , response.

i think there's no path in context anymore after clipped it.just fill rectangle:

//cgcontextfillpath(context); cgcontextfillrect(context, rect); 

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 -