Created
October 19, 2014 12:49
-
-
Save evgeniyd/f968de060c9858f9429a to your computer and use it in GitHub Desktop.
Factory method to capture view's screenshot and return a UIImage object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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