To expand the response, create a mask with a completely opaque center, and the edges should be shifted towards transparency, and then use the following code to mask
- (UIImage*) maskImage:(UIImage *)image withMask:(UIImage *)maskImage { CGImageRef imgRef = [image CGImage]; CGImageRef maskRef = [maskImage CGImage]; CGImageRef actualMask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, false); CGImageRef masked = CGImageCreateWithMask(imgRef, actualMask); return [UIImage imageWithCGImage:masked]; }
source share