开发者

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

开发者 https://www.devze.com 2023-01-17 02:08 出处:网络
I\'m putting an image into a CALayer that could be irregularly transparent: theCardLayer.front = [CALayer layer];

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 t开发者_C百科hat 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?


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.


You can use a CGShapeLayer. Set it's path to the shape you want to draw. You can also use shape layers as masks for other layers, if that's what you want.

0

精彩评论

暂无评论...
验证码 换一张
取 消