Last active
August 29, 2015 13:59
-
-
Save bleft/10881428 to your computer and use it in GitHub Desktop.
UIImage from View
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
+ (UIImage *)imageFromView:(UIView *)view | |
{ | |
if ([[UIScreen mainScreen] respondsToSelector:@selector(scale)]) { | |
if ([[UIScreen mainScreen] scale] == 2.0) { | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 2.0); | |
} else { | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0); | |
} | |
} else { | |
UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, 1.0); | |
} | |
BOOL hidden = [view isHidden]; | |
[view setHidden:NO]; | |
[[view layer] renderInContext:UIGraphicsGetCurrentContext()]; | |
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); | |
UIGraphicsEndImageContext(); | |
[view setHidden:hidden]; | |
return image; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment