ios - Drawing a polygon with one color for stroke, and a different one for fill? -
i'm having trouble drawing lines stroked color , filling insides (they make polygon) one.
uicolor *housebordercolor = [uicolor colorwithred:(170/255.0) green:(138/255.0) blue:(99/255.0) alpha:1]; cgcontextsetstrokecolorwithcolor(context, housebordercolor.cgcolor); cgcontextsetlinewidth(context, 3); // draw polygon cgcontextmovetopoint(context, 20, viewheight-19.5); cgcontextaddlinetopoint(context, 200, viewheight-19.5); // base cgcontextaddlinetopoint(context, 300, viewheight-119.5); // right border cgcontextaddlinetopoint(context, 120, viewheight-119.5); cgcontextaddlinetopoint(context, 20, viewheight-19.5); // fill cgcontextsetrgbfillcolor(context, (248/255.0), (222/255.0), (173/255.0), 1); //cgcontextfillpath(context); // stroke cgcontextstrokepath(context);
with cgcontextstrokepath
commented out, result:
but if uncomment cgcontextstrokepath
, fill out polygon, color overflows strokes:
how achieve result (without having redo whole drawing procedure twice):
you can use
cgcontextdrawpath(context, kcgpathfillstroke);
instead of
cgcontextfillpath(context); cgcontextstrokepath(context);
the problem both cgcontextfillpath()
, cgcontextstrokepath(context)
clear current path, first operation succeeds, , second operation draws nothing. cgcontextdrawpath()
combines fill , stroke without clearing path in between.
Comments
Post a Comment