我想知道,如何删除 UIView
的自定义矩形(例如,IB
中的 UIImageView
或其他)为了显示另一个UIImageView
位于下方。
我没有设法使用论坛中的一些响应来做到这一点......
最佳答案
这将清除图像中的一个矩形:
- (UIImage *)clearRect:(CGRect)rect inImage:(UIImage *)image {
if (UIGraphicsBeginImageContextWithOptions != NULL)
UIGraphicsBeginImageContextWithOptions([image size], NO, 0.0);
else
UIGraphicsBeginImageContext([image size]);
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:CGRectMake(0.0, 0.0, [image size].width, [image size].height)];
CGContextClearRect(context, rect);
UIImage *result = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return result;
}
只需加载您的图像并在将其分配给 ImageView 之前清除矩形:
UIImage *image = [UIImage imageNamed:@"Image.png"];
UIImage *maskedImage = [self clearRect:CGRectMake(10.0, 10.0, 50.0, 50.0) inImage:image];
[imageView setImage:maskedImage];
关于iphone - 删除 UIImageView 的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6311862/