如何在iOS上的UIImage中删除rect?

时间:2012-04-30 09:55:11

标签: ios xcode uiimageview mask

如何删除UIImage中的矩形区域?我的想法是我有一个纯色图像和一个CGRect矩形,我想删除UIImage中的CGrect,以便CGRect区域是透明的。请参考下图。半红色是我的uiimage,我想删除中间的矩形,以便我可以透明地查看背景图像。

Example

2 个答案:

答案 0 :(得分:0)

CGContextClearRect(context,your_rect)

答案 1 :(得分:0)

UIImage *yourImage;
CGRect imageRect = CGRectMake(0, 0, yourImage.size.width, yourImage.size.height);
CGRect grayRect = CGRectMake(20, 20, 20, 20);
CGRect rects[2] = {
  imageRect,
  grayRect
};
CGContextClipToRects(context, rects, 2);
[yourImage drawInRect:imageRect];