Add the following variables to the ViewController.h file -
CAShapeLayer *fillLayer; UIVisualEffectView *overlayView;
Add the following methods to the ViewController.m file:
-(void)addOverlay:(CGRect)rect{ float x = rect.origin.x; float y = rect.origin.y; UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height) cornerRadius:0]; UIBezierPath *circlePath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(x, y, rect.size.width, rect.size.height) cornerRadius:5]; [path appendPath:circlePath]; [path setUsesEvenOddFillRule:YES]; [self removeOverlay]; overlayView = [[UIVisualEffectView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height+64)]; overlayView.backgroundColor = [UIColor clearColor]; [self.view addSubview:overlayView]; fillLayer = [CAShapeLayer layer]; fillLayer.path = path.CGPath; fillLayer.fillRule = kCAFillRuleEvenOdd; fillLayer.fillColor = [UIColor colorWithRed:78/255.0 green:103/255.0 blue:135/255.0 alpha:1.0].CGColor; fillLayer.opacity = 0.85; [[UIApplication sharedApplication].keyWindow.layer addSublayer:fillLayer]; } -(void)removeOverlay{ [overlayView removeFromSuperview]; [fillLayer removeFromSuperlayer]; }
and name it like
[self addOverlay:rect]
source share