开发者

How do I use a mask to punch out my image?

I have a mask (loaded from a 256 grey PNG) that I want to apply to an image that's being used as part of my process for drawing a UITableViewCell's imageView.image property.

When the cell isn't selected/highlighted, I CGImageCreateWithMask with a square of the proper color and the mask, then drawAtPoint: it into the image I'm building. This works fine.

However, when the cell is selected or highlighted, I'd like to instead use the mask to instead punch through my image appropriately. That is, when my mask specifies full opacity, I want the image I'm building to be completely transparent so the tableview's back开发者_如何学Pythonground is drawn through it. Where my mask specifies 0 opacity, I want the alpha channel untouched. I want nothing other than the alpha channel affected.

I guess what I mean is that I want to draw clearColor over a UIImage, with a varying level of opacity according to a mask.

First, what is this called? And second, how do I do it?


I think you have to manipulate the CALayers for that. You can use the mask property of the cell's CALayer : CALayer mask attribute.

That is, something in the way of (if myMask is descendent of UIView) :

myCell.layer.mask = myMask.layer
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜