Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active August 29, 2015 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KentarouKanno/36dee31444ac2a332b60 to your computer and use it in GitHub Desktop.
Save KentarouKanno/36dee31444ac2a332b60 to your computer and use it in GitHub Desktop.
// UIViewをUIImageに変換する(objective-c)
- (UIImage*)convertUIimageFromUIview:(UIView*)view {
UIGraphicsBeginImageContext(view.frame.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
// UIViewをUIImageに変換する(Swift)
func convertUIimageFromUIview(view: UIView) -> UIImage {
UIGraphicsBeginImageContext(view.frame.size)
view.layer .renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment