I'm using this Swift code to take a screenshot of my app:
UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size, false, 0);
self.view.drawViewHierarchyInRect(view.bounds, afterScreenUpdates: true)
var image:UIImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
How would I go about taking a screenshot of only part of the screen, and not all of it, as I do here?
I think this is the best Answer to take a shot of part of the screen:
To snapshot a view containing a UIVisualEffect (Blur/Vibrancy), see my solution here: https://stackoverflow.com/a/33633386/802196
For example if you want to take the screen shot of the
UIView
rectangle at position(50,50)
with height of(100,150)
.First set the Image Context to the size of the rectangle. This sets the image size.
Now draw the view in this context in such a way that, the visible part of the screenshot starts at
(50,50)
This clips the screen shot at
(100,150)
because we set the size of ourcontext
. Now take the UIImage from this.