Skip to content

Instantly share code, notes, and snippets.

@motokiee
Last active August 29, 2015 14:20
Show Gist options
  • Save motokiee/95a13b65c0c759d9f248 to your computer and use it in GitHub Desktop.
Save motokiee/95a13b65c0c759d9f248 to your computer and use it in GitHub Desktop.
UIView Extension
/**
* xibからviewオブジェクトを取り出す
*/
extension UIView {
class func loadFromNibNamed(nibNamed: String, bundle : NSBundle = NSBundle.mainBundle()) -> UIView! {
return UINib(nibName: nibNamed, bundle: bundle).instantiateWithOwner(nil, options: nil)[0] as? UIView
}
class func screenCapture(view: UIView) -> UIImage {
var captureImage: UIImage
UIGraphicsBeginImageContextWithOptions(view.frame.size, false, UIScreen.mainScreen().scale)
view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
captureImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return captureImage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment