In ActionScript 3 we can apply a mask of to a visual object like this:
SomeVisualObject.mask = maskShapeObject;
How can I achieve similar result in Objective-C? Assume I have two UIImageView
objects, I want something like this:
imageView1.mask = imageView2;
How can I use one UIImageView
to mask, or clip the shape of, another?
CALayer *maskLayer = [CALayer layer];
UIImage *maskImage = [UIImage imageNamed:@"maskImage.png"];
maskLayer.contents = (id)maskImage.CGImage;
maskLayer.bounds = (CGRect){CGPointZero, maskImage.size};
UIImageView *imageViewToMask = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
imageViewToMask.image = [UIImage imageNamed:@"image2.png"];
imageViewToMask.layer.mask = maskLayer;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With