I want to create a mask path whose final output will be a corner with a concave face.
I have created a UIBezierPath
using the -bezierPathWithRoundedRect:byRoundingCorners:cornerRadii:
method and specified that only one corner need to be rounded (in this example, the UIRectCornerBottomLeft
) and I thought that by reversing this path, I should get what would have been cut in the first place.
For this, I am trying -bezierPathByReversingPath
but it doesn't seem to make any difference (with or without as I am getting the normal bezier path and not the reversed)
This is what I have tried so far:
UIView *vwTest = [[UIView alloc] init];
[vwTest setFrame:CGRectMake(100.0f, 100.0f, 100.0f, 100.0f)];
[vwTest setBackgroundColor:[UIColor redColor]];
[self.view addSubview:vwTest];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:vwTest.bounds
byRoundingCorners:UIRectCornerBottomLeft
cornerRadii:CGSizeMake(50.0f, 50.0f)];
//get reverse path but doesn't seem to work as I think it should
maskPath = [maskPath bezierPathByReversingPath];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setFrame:vwTest.bounds];
[maskLayer setPath:maskPath.CGPath];
[vwTest.layer setMask:maskLayer];
[vwTest.layer setMasksToBounds:YES];
[vwTest setNeedsDisplay];
As per the image below, what I am trying to achieve is to show the red part of the UIView
and eliminate the rest of the area.
For the time being, I am doing shit like subview on subview and syncing the color of one subview with the main view's background color (sucks but atleast I got the required output):
[self.view setBackgroundColor:[UIColor lightGrayColor]];
UIView *vwTest = [[UIView alloc] init];
[vwTest setFrame:CGRectMake(100.0f, 100.0f, 100.0f, 100.0f)];
[vwTest setBackgroundColor:[UIColor redColor]];
[self.view addSubview:vwTest];
UIView *vwPatch = [[UIView alloc] init];
[vwPatch setFrame:vwTest.bounds];
[vwPatch setBackgroundColor:vwTest.superview.backgroundColor];
[vwTest addSubview:vwPatch];
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:vwPatch.bounds
byRoundingCorners:UIRectCornerBottomLeft
cornerRadii:CGSizeMake(50.0f, 50.0f)];
CAShapeLayer *maskLayer = [CAShapeLayer layer];
[maskLayer setFrame:vwPatch.bounds];
[maskLayer setPath:maskPath.CGPath];
[vwPatch.layer setMask:maskLayer];
[vwPatch.layer setMasksToBounds:YES];
[vwPatch setNeedsDisplay];
Someone, kindly point me in the right direction.