Created
September 6, 2017 09:45
-
-
Save iAmrSalman/b1fe42441077b3cab53aea885bd9b40e to your computer and use it in GitHub Desktop.
[Image from view] #swift3 #uiimage #uiview
This file contains hidden or 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
| extension UIImage{ | |
| convenience init(view: UIView) { | |
| UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.isOpaque, 0.0) | |
| view.drawHierarchy(in: view.bounds, afterScreenUpdates: false) | |
| let image = UIGraphicsGetImageFromCurrentImageContext() | |
| UIGraphicsEndImageContext() | |
| self.init(cgImage: (image?.cgImage)!) | |
| } | |
| } | |
| //Use : | |
| //myView is completly loaded/visible , calling this code after only after viewDidAppear is call | |
| imgVV.image = UIImage.init(view: myView) | |
| // Simple image object | |
| let img = UIImage.init(view: myView) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment