Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Darken an Irregularly Shaped Transparent CALayer on the iPhone?

I'm putting an image into a CALayer that could be irregularly transparent:

 theCardLayer.front = [CALayer layer];
 theCardLayer.front.contents = (id)[cardDrawing CGImage];

In other words, it might be a square filling the layer or it might be an octagon that leaves the corners see-through.

I want to sometimes darken this layer, but without darkening the see-through bits. Any suggestions for how to do so in a programmatic way?

like image 961
Shannon A. Avatar asked Nov 14 '22 07:11

Shannon A.


1 Answers

Take a look at CGBlendMode; a multiply blend, done by creating a new CGBitmapContext, drawing the image and then a grey fill, and assigning the resulting image to your layer, should work nicely.

like image 92
Ben Stiglitz Avatar answered Dec 10 '22 15:12

Ben Stiglitz