user615431
user615431

Reputation: 1

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! What are the code and frameworks needed?

Upvotes: 0

Views: 468

Answers (1)

Rog
Rog

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

Related Questions