I am wondering how my iPhone app can take a screen shot of a specific UIView
as a UIImage
.
I tried this code but all I get is a blank image.
UIGraphicsBeginImageContext(CGSizeMake(320,480));
CGContextRef context = UIGraphicsGetCurrentContext();
[myUIView.layer drawInContext:context];
UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
myUIView
has dimensions 320x480 an it has some sub-views.
What is the correct way to do this?
Swift 4 updated :
This method may put in your Controller class.
Apple does not allow:
Applications should take a screenshot using the
drawRect
method as specified in: http://developer.apple.com/library/ios/#qa/qa2010/qa1703.htmlDetails
xCode 8.2.1, Swift 3
UIView Screen Shot in Swift
Usage
Сomplete example of the use
Result
Apple now allows us to use it in a public application, even though it's a private API