I’ve created a UIView
with a semi-transparent black background to sit across my main app’s view. What I’m aiming for here is to create a cut-out circle shape so
If You are using any Black Image to mask then
-(void)maskWithImage:(UIImage*)maskImage toImageView:(UIImageView*)imgView{
CALayer *aMaskLayer=[CALayer layer];
aMaskLayer.contents=(id)maskImage.CGImage;
imgView.layer.mask=aMaskLayer;
}
If you have any Custom ShapeLayer to mask
-(void)maskWithShapeLayer:(CALayer*)layer toImageView:(UIImageView*)imgView{
//Layer should be filled with Black color to mask those part of Image
imgView.layer.mask=layer;
}
If You want to make ImageView Mask with Circle
-(void)maskWithCircle:(UIImageView*)imgView{
CAShapeLayer *aCircle=[CAShapeLayer layer];
aCircle.path=[UIBezierPath bezierPathWithRoundedRect:imgView.bounds cornerRadius:imgView.frame.size.height/2].CGPath; // Considering the ImageView is square in Shape
aCircle.fillColor=[UIColor blackColor].CGColor;
imgView.layer.mask=aCircle;
}