objective c - Don't display subviews outside of UIBezierPath -
objective c - Don't display subviews outside of UIBezierPath -
i have 1 uiview drawn with:
- (void)drawrect:(cgrect)rect { uibezierpath *bezierpath = [uibezierpath bezierpathwithovalinrect:cgrectmake(0, 0, self.widthofline, self.heightofline)]; [bezierpath fill]; }
and frame centered within ios window. want place bunch of smaller (5px 5px) views within view randomly, doing fine arc4random() function , drawing views. however, can't seem figure out how cutting off views outside bezierpathwithovalinrect, display them everywhere in first uiview's frame. know this?
edit:
for clarity, have defined view as:
- (void)drawrect:(cgrect)rect { uibezierpath *drawpath = [uibezierpath bezierpathwithovalinrect:cgrectmake(self.xposition, self.yposition, self.width, self.width)]; [[uicolor whitecolor] setfill]; [drawpath fill]; }
and adding big number of these first view subviews, want them not displayed outside oval bezier path. there way a) add together them within oval bezier path opposed within entire frame, or b) way clip outside oval view?
in order clip subviews particular uibezierpath, you'll want set mask property of view's layer property. if set layer.mask cashapelayer of path, subviews cropped path.
i utilize next code in app:
// create view that'll hold subviews // need clipped path cgrect anyrect = ...; uiview* clippedview = [[uiview alloc] initwithframe:anyrect]; clippedview.clipstobounds = yes; // create shape layer we'll utilize clip cashapelayer* maskinglayer = [cashapelayer layer]; [maskinglayer setpath:bezierpath.cgpath]; maskinglayer.frame = backingimageholder.bounds; // set mask property of layer, , // create sure subviews visible within // path clippedview.layer.mask = maskinglayer; // subviews add together won't show outside of path uiview* anysubview = ...; [clippedview addsubview:anysubview];
objective-c cocoa uiview uibezierpath
Comments
Post a Comment