IOS 截屏

2017-11-10  本文已影响0人  UILable攻城狮
-(void) screenShot{

  UIGraphicsBeginImageContext(self.bounds.size);   //self为需要截屏的UI控件 即通过改变此参数可以截取特定的UI控件 
  [self.layer renderInContext:UIGraphicsGetCurrentContext()];    
  UIImage *image= UIGraphicsGetImageFromCurrentImageContext();
  UIGraphicsEndImageContext();    
  NSLog(@"image:%@",image); //至此已拿到image

  UIImageView *imaView = [[UIImageView alloc] initWithImage:image];   
  imaView.frame = CGRectMake(0, 700, 500, 500);    
  [self addSubview:imaView];    

  UIImageWriteToSavedPhotosAlbum(image, self, nil, nil);//把图片保存在本地
}
// 调用最后一行代码的时候需要在plist中添加这行代码:Privacy - Photo Library Usage Description
上一篇下一篇

猜你喜欢

热点阅读