Skip to content

Instantly share code, notes, and snippets.

@evgeniyd
Created October 19, 2014 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evgeniyd/f968de060c9858f9429a to your computer and use it in GitHub Desktop.
Save evgeniyd/f968de060c9858f9429a to your computer and use it in GitHub Desktop.
Factory method to capture view's screenshot and return a UIImage object
import UIKit
extension UIImage {
public class func imageWithScreenshotFromView(view: UIView) -> UIImage! {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, false, UIScreen.mainScreen().scale)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment