在iPhone上,有没有办法点击圆角矩形按钮并截取屏幕截图,我不希望我的用户通过按下sleep + home按钮拍照!需要什么代码和框架?
答案 0 :(得分:3)
这是一个Class方法,它将返回你传递给它的UIView和CGRect的UIImage:
+ (UIImage *)captureView:(UIView *)view withArea:(CGRect)screenRect {
UIGraphicsBeginImageContext(screenRect.size);
CGContextRef ctx = UIGraphicsGetCurrentContext();
[[UIColor blackColor] set];
CGContextFillRect(ctx, screenRect);
[view.layer renderInContext:ctx];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}