I‘m trying to create a simple example of drawing an image to a layer, and then setting that layer‘s alpha mask. I added the code below to my sample app‘s viewDidLoad. without setting the mask, i can see the image of the leaf. after i set the mask, i see nothing where my sublayer was. what am i doing wrong?
Here are the two images i‘m using (just samples i found on the net) http://sorenworlds.netfirms.com/Alpha/leaf.jpg
http://sorenworlds.netfirms.com/Alpha/leaf-alfa.jpg
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 20.0;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 20, 20);
CALayer *sublayer = [CALayer layer];
sublayer.backgroundColor = [UIColor blueColor].CGColor;
sublayer.shadowOffset = CGSizeMake(0, 3);
sublayer.shadowRadius = 5.0;
sublayer.shadowColor = [UIColor blackColor].CGColor;
sublayer.shadowOpacity = 0.8;
sublayer.frame = CGRectMake(30, 30, 128, 192);
[self.view.layer addSublayer:sublayer];
CGImageRef img = [UIImage imageNamed:@"leaf.jpg"].CGImage;
sublayer.borderColor = [UIColor blackColor].CGColor;
sublayer.borderWidth = 2.0;
sublayer.contents = img;
CGImageRef imgAlpha = [UIImage imageNamed:@"leaf_alpha.jpg"].CGImage;
CALayer *alphaLayer = [CALayer layer];
alphaLayer.contents = (id)imgAlpha;
sublayer.mask = alphaLayer;
Any help is greatly appreciated.