二、代码示例
storyboard界面搭建
代码:
复制代码//
// YYViewController.m
// 01-截屏
//
// Created by apple on 14-6-12.
// Copyright (c) 2014年 itcase. All rights reserved.
//
#import "YYViewController.h"
#import "MBProgressHUD+NJ.h"
@interface YYViewController ()
@property (weak, nonatomic) IBOutlet UIView *contentView;
- (IBAction)BtnClick:(UIButton *)sender;
@end
复制代码
@implementation YYViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (IBAction)BtnClick:(UIButton *)sender {
//延迟两秒保存
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//获取图形上下文
// UIGraphicsBeginImageContext(self.view.frame.size);
UIGraphicsBeginImageContext(self.contentView.frame.size);
//将view绘制到图形上下文中
// [self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
[self.contentView.layer renderInContext:UIGraphicsGetCurrentContext()];
//将截屏保存到相册
UIImage *newImage=UIGraphicsGetImageFromCurrentImageContext();
UIImageWriteToSavedPhotosAlbum(newImage,self, @selector(image:didFinishSavingWithError:contextInfo:), nil);











