What is the way to take a screenshot in app on iOS?
On iPhone, is there a way to tap a rounded rect button and take a screenshot, I don't want my users taking a photo by pressing sleep+home button! 开发者_如何学PythonWhat are the code and frameworks needed?
Here's a Class method that will return a UIImage of the UIView and CGRect you pass to it:
+ (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;
}
精彩评论