Create UIImage from shadowed view while retaining alpha?

前端 未结 3 1693
温柔的废话
温柔的废话 2020-12-22 03:17

I have a somewhat unusual problem. In my app, I am shadowing a UIImageView using basic Quartz2d layer shadowing. Here\'s my code:

imageView.la         


        
3条回答
  •  感动是毒
    2020-12-22 03:49

    Try setting your UIImageView's backgroundColor to [UIColor clearColor] - this may enable your current solution to work.

    imageView.backgroundColor = [UIColor clearColor];
    UIGraphicsBeginImageContext(CGSizeMake(320, 396)); 
    [imageView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    

    Source: Converting a CGLayer to a *transparent* UIImage and PNG file in CoreGraphics iphone

提交回复
热议问题