YAScreenShotClass.h
#import <Foundation/Foundation.h> #import <QuartzCore/QuartzCore.h> @interface YAScreenShotClass : NSObject +(UIImage *)screenShotFrom:(UIView *)view frame:(CGRect)frame; @end
YAScreenShotClass.m
#import "YAScreenShotClass.h" @implementation YAScreenShotClass +(UIImage *)screenShotFrom:(UIView *)view frame:(CGRect)frame { if(UIGraphicsBeginImageContextWithOptions != NULL) { UIGraphicsBeginImageContextWithOptions(frame.size, NO, 0.0); } else { UIGraphicsBeginImageContext(frame.size); } //获取图像 [view.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } @end