5

我正在为 UITableViewCell 上的“UIImageView”属性动态创建一个(绘制我自己的自定义)UIImage。

当用户选择 tableView 单元格时,单元格背景会变为蓝色,但我的自定义 UIImage 背景不会 - 它仍然是白色的(所以很明显我有一张图片坐在那里)。我尝试了各种绘图方法

// when I create the cell
cell.imageView.backgroundColor = [UIColor clearColor];
cell.imageView.opaque = NO;

// 1. when I create the UIImage - clearColor background
CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
CGContextFillRect(context, rect);

// 2. when I create the UIImage - clear background
CGContextClearRect(context, rect);

但是在这两种方法中,背景都是黑色的。唯一可行的方法是完成图像的创建,然后根据第一张图像应用“CGImageCreateWithMaskingColors”创建第二张图像 - 屏蔽背景。

有没有办法我可以首先“绘制”透明背景?

4

1 回答 1

10

确保在设置图像上下文时传递NO给函数的opaque参数。UIGraphicsBeginImageContextWithOptions

于 2012-11-22T19:51:13.670 回答