2

我有一个蒙版(从 256 灰色 PNG 加载),我想将其应用于图像,该图像被用作绘制 a属性的过程的一部分。UITableViewCellimageView.image

当未选择/突出显示单元格时,我CGImageCreateWithMask使用正确颜色的正方形和蒙版,然后drawAtPoint:将其放入我正在构建的图像中。这工作正常。

However, when the cell is selected or highlighted, I'd like to instead use the mask to instead punch through my image appropriately. 也就是说,当我的蒙版指定完全不透明度时,我希望我正在构建的图像完全透明,以便通过它绘制 tableview 的背景。在我的蒙版指定 0 不透明度的地方,我希望 alpha 通道保持不变。除了受影响的 Alpha 通道,我什么都不想要。

我想我的意思是我想在 a 上绘制 clearColor UIImage,根据蒙版具有不同程度的不透明度。

首先,这叫什么?第二,我该怎么做?

4

1 回答 1

1

我认为您必须为此操作 CALayers。您可以使用单元格的 CALayer 的 mask 属性:CALayer mask 属性

也就是说,(如果 myMask 是 UIView 的后代)的方式:

myCell.layer.mask = myMask.layer
于 2009-12-11T23:02:28.327 回答