#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
@interface UIView (Screenshot)
- (UIImage *)screenshot;
@end
#import "UIView+Screenshot.h"
@implementation UIView (Screenshot)
- (UIImage *)screenshot
{
UIGraphicsBeginImageContext(self.bounds.size);
[[UIColor clearColor] setFill];
[[UIBezierPath bezierPathWithRect:self.bounds] fill];
CGContextRef ctx = UIGraphicsGetCurrentContext();
[self.layer renderInContext:ctx];
UIImage *anImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return anImage;
}
@end
Добавьте вышеуказанную категорию UIView и просто используйте
UIImage *image = [self.view screenshot];