ios - Quartz and clipping area -
i have question quartz , clipping area:
i have rectangle inside rectangle have rectangle b filling of b dveve cut in a: pierced b. best way in quartz? did not understand how clipping
if understand correctly, want draw smaller rectangle inside larger rectangle inner rectangle transparent. can achieve drawing cashapelayer path contains both rectangles subpaths. don't forget set layer's fill rule kcafillruleevenodd
.
try this:
cgrect recta = cgrectmake(100, 100, 200, 200); cgrect rectb = cgrectmake(150, 150, 100, 100); uibezierpath *path=[[uibezierpath alloc] init]; // add sub-path recta [path movetopoint:cgpointmake(recta.origin.x, recta.origin.y)]; [path addlinetopoint:cgpointmake(recta.origin.x+recta.size.width, recta.origin.y)]; [path addlinetopoint:cgpointmake(recta.origin.x+recta.size.width, recta.origin.y+recta.size.height)]; [path addlinetopoint:cgpointmake(recta.origin.x, recta.origin.y+recta.size.height)]; [path closepath]; // add sub-path rectb [path movetopoint:cgpointmake(rectb.origin.x, rectb.origin.y)]; [path addlinetopoint:cgpointmake(rectb.origin.x+rectb.size.width, rectb.origin.y)]; [path addlinetopoint:cgpointmake(rectb.origin.x+rectb.size.width, rectb.origin.y+rectb.size.height)]; [path addlinetopoint:cgpointmake(rectb.origin.x, rectb.origin.y+rectb.size.height)]; [path closepath]; // create cashapelayer path cashapelayer *pathlayer = [cashapelayer layer]; [pathlayer setfillrule:kcafillruleevenodd]; /* <- important! */ [pathlayer setpath:path.cgpath]; [pathlayer setfillcolor:[uicolor blackcolor].cgcolor]; // add cashapelayer view [someview.layer addsublayer:pathlayer];
Comments
Post a Comment