iphone - 删除 UIImageView 的矩形

标签 iphone objective-c ios ipad uiimageview

我想知道,如何删除 UIView 的自定义矩形(例如,IB 中的 UIImageView 或其他)为了显示另一个UIImageView位于下方。


enter image description here

我没有设法使用论坛中的一些响应来做到这一点......

最佳答案

这将清除图像中的一个矩形:

- (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/

相关文章:

ios - 我怎样才能把两个委托(delegate)给一个 View Controller

iphone - 如何更改自定义 MKAnnotationView 的框架位置?

ios - 隐藏 UICollectionViewCell

ios - iOS OpenGL ES 3.0 上的转换反馈变量重新声明错误

ios - 设置每周调用的通知

javascript - iOS:在 UIWebview 中使用 javascript 调用 obj-c 方法

iphone - img_data_lock iPhone - imageNamed 与 imageWithContentsofFile

iphone - iOS 模拟器只列出最新的 iOS 版本。如何设置早期版本

带有类方法的 Objective-C 点符号?

objective-c - 如何在 Objective-c 的宏中定义数组?