Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer mask removing?

I know a mask is added with something like

UIImageView *mask = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mask.png"]];
[mask setFrame:kHexagonMaskRect];
[self setBackgroundColor:kBackgroundColor];
[self layer].mask = [mask layer];
[mask release];

But how do I remove it? Setting it to nil works, but that is leaking.

like image 661
Tudor Avatar asked May 04 '12 08:05

Tudor


1 Answers

#import <QuartzCore/QuartzCore.h>

Add mask

UIImageView *maskimageview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"mask.png"]];
CALayer *mask = [CALayer layer];
mask.contents = (id)[[UIImage imageNamed:@"mask.png"] CGImage];
maskimageview.layer.mask = mask;
maskimageview.layer.masksToBounds = YES;

Remove mask

 maskimageview.layer.mask = nil;

Hope, this will help you..

like image 174
Nitin Avatar answered Sep 22 '22 09:09

Nitin