Created
April 2, 2019 15:44
-
-
Save bigsan/a9155948cfbb384a2a6240ca597163bf to your computer and use it in GitHub Desktop.
UIImage extension that creates a UIImage from a 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 { | |
// UIImage extension that creates a UIImage from a UIView | |
convenience init (view:UIView) { | |
UIGraphicsBeginImageContext(view.frame.size) | |
view.layer.render(in: UIGraphicsGetCurrentContext()!) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
self.init(cgImage: image!.cgImage!) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment