iOS开发中难免会有PM说要再项目中,实现截屏,还分享出去,这里就把截屏的代码贴出来。
分享的话,就相当于只是把这种截屏的图片保存起来,到时候,分享的时候,把图片传过去
#import <QuartzCore/QuartzCore.h>
添加QuartzCore.framework库
-(void) screenShotAction
{
UIGraphicsBeginImageContext(self.bounds.size);
[self.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *imaView = [[UIImageView alloc] initWithImage:image];
imaView.frame = CGRectMake(0, 0, 500, 500);
[self addSubview:imaView];
//写入相册
UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);
}