【问题标题】:UIImageView round corner has white backgroundUIImageView 圆角有白色背景
【发布时间】:2011-12-02 09:10:42
【问题描述】:

圆角有白色背景。 我关注了其他 SO 答案,但不知道为什么我会得到这个 whites

下面是代码。

UIView* testView = [[[UIView alloc] initWithFrame: self.animationView.bounds] autorelease];
UIImageView* testImageView = [[[UIImageView alloc] initWithImage:backImage] autorelease];
[testView addSubview: testImageView];
testImageView.backgroundColor = [UIColor clearColor];

CALayer* layer = [testView layer];
bool prev = layer.masksToBounds;
layer.masksToBounds = YES;
layer.cornerRadius = 30;
testView.clipsToBounds = YES;
UIImage* image = [UIImage captureView: testView];
//this image has the white regions in the four corners.
// when seen on iphone photo album


+ (UIImage*)captureView:(UIView*)view
{   
    CGSize size = view.bounds.size;
    CGContextRef context = CreateARGBBitmapContext(size);
    CGContextTranslateCTM(context, 0, size.height);
    CGContextScaleCTM(context, 1.0, -1.0);
    [view.layer renderInContext: context];
    CGImageRef imageRef = CGBitmapContextCreateImage(context);
    UIImage* img = [UIImage imageWithCGImage: imageRef];
    CGImageRelease(imageRef);
    CGContextRelease(context);
    return img;
}

【问题讨论】:

    标签: iphone background rounded-corners


    【解决方案1】:

    可能你必须设置testImageView.opaque = NO

    【讨论】:

      【解决方案2】:

      添加[testImageView setClipsToBounds:YES]

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-28
        • 2010-12-27
        • 2021-11-10
        • 1970-01-01
        • 2013-04-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多