0
votes

I'd like to create a UIView that has rounded corners on the top left and top right.

In order to do that, i'd like to mask the UIView with a CAShapeLayer.

This is the code I am using:

UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.menuContainerView.bounds
                                               byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight
                                                     cornerRadii:CGSizeMake(20.0, 20.0)];

CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = self.menuContainerView.bounds;
maskLayer.path = maskPath.CGPath;

self.menuContainerView.layer.mask = maskLayer;

however, when i run this code, it appears that the mask has no effect. Any ideas why not?

1

1 Answers

0
votes

What I did not mention in my answer is that I was also setting the same maskLayer as the mask to another view (one offscreen). Apparently you can't do this.... i removed that extra line

self.otherContainerView.layer.mask = maskLayer;

and it worked as desired.