Reputation: 1
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! What are the code and frameworks needed?
Upvotes: 0
Views: 468
Reputation: 18670
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;
}
Upvotes: 3