ios - clip-masking uiview with CAShapeLayer and UIBezierPath -


i have problem clipping view using cashapelayer-uibezierpath , want clip content end getting stroke (frame) uibezierpath , code

uibezierpath *path2path = [uibezierpath bezierpath]; [path2path movetopoint:cgpointmake(206.745, 0)]; [path2path addlinetopoint:cgpointmake(206.745, 97.613)]; [path2path addlinetopoint:cgpointmake(0, 97.613)]; [path2path addlinetopoint:cgpointmake(0, 0)]; [path2path addlinetopoint:cgpointmake(87.28, 0)]; [path2path addcurvetopoint:cgpointmake(103.808, 12.118) controlpoint1:cgpointmake(87.28, 0) controlpoint2:cgpointmake(86.555, 12.118)]; [path2path addcurvetopoint:cgpointmake(119.466, 0) controlpoint1:cgpointmake(121.061, 12.118) controlpoint2:cgpointmake(119.466, 0)]; [path2path addlinetopoint:cgpointmake(206.745, 0)]; [path2path closepath];  [path2path addclip];  cashapelayer *pathlayer = [cashapelayer layer]; pathlayer.frame=myview.bounds; pathlayer.path = path2path.cgpath;  pathlayer.strokecolor = [[uicolor blackcolor] cgcolor]; pathlayer.fillcolor = [[uicolor clearcolor] cgcolor];  pathlayer.fillrule=kcafillruleevenodd; [myview.layer setmask:pathlayer]; [myview.layer setmaskstobounds:yes];  myview.backgroundcolor=[uicolor greencolor]; 

the result of code green stroke line ,the bounds empty , http://i.stack.imgur.com/aehdo.png

however , want make bounds green , clipped stroke

as rob mayoff said you can setting view's layer mask cashapelayer.

uibezierpath *myclippingpath = ... cashapelayer *mask           = [cashapelayer layer]; mask.path                    = myclippingpath.cgpath; myview.layer.mask            = mask; 

in swift

let myclippingpath = uibezierpath( ... ) let mask           = cashapelayer() mask.path          = myclippingpath.cgpath layer.mask         = mask 

Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -