tags:

views:

58

answers:

2

I've heard that it's possible to mask views with black/white images, where black means fully transparent and white means view is visible. The big difference to clipsToBounds is that the view could be clipped in funny shapes like circles or stars. How could I do that?

+2  A: 

Look at a function

void CGContextClipToMask (
   CGContextRef c,
   CGRect rect,
   CGImageRef mask
);

If I understood correctly it does exactly what you want.

Alexander Babaev
+1  A: 
CGImageRef maskRef = <some cgimage>; 
CGImageRef mask = CGImageMaskCreate(CGImageGetWidth(maskRef), CGImageGetHeight(maskRef), CGImageGetBitsPerComponent(maskRef), CGImageGetBitsPerPixel(maskRef), CGImageGetBytesPerRow(maskRef), CGImageGetDataProvider(maskRef), NULL, YES);
CGContextClipToMask(context, maskRect, mask);
CGImageRelease(mask);
Amorya