ios - CGContextRef and even-odd fill rule -


i need paint series of path in cgcontext block. these path drawn user can not determine direction. use following code snippet draw path:

cgcontextsavegstate(context); uibezierpath *fillpath = [ uibezierpath bezierpath ];  ( uibezierpath *path in arrayofpaths ) {     [ fillpath appendpath:path ]; }  cgcontextaddpath(context, fillpath.cgpath ); cgcontextsetfillcolorwithcolor( context, [[uicolor greencolor ] colorwithalphacomponent:0.3 ].cgcolor ); cgcontextfillpath(context); 

however if paths created in reverse directions resulting drawing seems produce drawing overlapping section knocked out, equivalent of setting even-odd rule yes.

any suggestions?

you surround lines fill each path cgcontextsavegstate/cgcontextrestoregstate instructions. way start "from scratch", ie. clean path stack, on each filling.

edit: i've got nice wrapping function this:

void cgcontextblock(cgcontextref ctx, void (^block)()) {     cgcontextsavegstate(ctx);     block();     cgcontextrestoregstate(ctx); } 

use that:

cgcontextsetfillcolorwithcolor(context, [uicolor greencolor].cgcolor); (uibezierpath *path in arrayofpaths) {     cgcontextblock(context, ^{         cgcontextaddpath(context, path.cgpath);         cgcontextfillpath(context);     }); } 

Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -