SHARE
TWEET

Capture an image of a view not yet displayed

priore Jul 9th, 2015 (edited) 649 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Capture an image of a view, inside of a ViewController with Xib, not yet displayed.
  2. // use:
  3. // CaptureViewController *viewController = [[CaptureViewController alloc] initWithNibName:@"CaptureViewController" bundle:nil];
  4. // [viewController loadView];
  5. // UIImage *img = [viewController capture];
  6. //
  7. - (UIImage*)capture {
  8.    
  9.     UIGraphicsBeginImageContext(self.view.bounds.size);
  10.     CGContextRef context = UIGraphicsGetCurrentContext();
  11.    
  12.     [self.view.layer renderInContext:context];
  13.    
  14.     UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
  15.     UIGraphicsEndImageContext();
  16.    
  17.     return img;
  18. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top