Skip to content

Instantly share code, notes, and snippets.

@bittz
Created August 24, 2016 10:10
Show Gist options
  • Save bittz/edb8b53d4bcf924c8cee548182641fd2 to your computer and use it in GitHub Desktop.
Save bittz/edb8b53d4bcf924c8cee548182641fd2 to your computer and use it in GitHub Desktop.
UIImage from UIView.
import UIKit
extension UIImage {
static func imageFromView(view: UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 0)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment