Skip to content

Instantly share code, notes, and snippets.

@iAmrSalman
Created September 6, 2017 09:45
Show Gist options
  • Select an option

  • Save iAmrSalman/b1fe42441077b3cab53aea885bd9b40e to your computer and use it in GitHub Desktop.

Select an option

Save iAmrSalman/b1fe42441077b3cab53aea885bd9b40e to your computer and use it in GitHub Desktop.
[Image from view] #swift3 #uiimage #uiview
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