1

I'm trying to find the right code to take a screenshot of the current View, specially a camera, through xcode but haven't found anything yet. I've started programming very recently and new to this community as well.

1 Answers1

0

You can take screenshot of full screen by using this code:

func captureView(view: UIView) -> UIImage {
    var screenRect: CGRect = UIScreen.mainScreen().bounds
    UIGraphicsBeginImageContext(screenRect.size)
    var ctx: CGContextRef = UIGraphicsGetCurrentContext()
    UIColor.blackColor().set()
    CGContextFillRect(ctx, screenRect)
    view.layer.renderInContext(ctx)
    var newImage: UIImage = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    return newImage
}
Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Abhinandan Pratap
  • 2,142
  • 1
  • 18
  • 39
  • 1
    To be clear, that will take a screenshot of your app's view(s), but not of anything outside of your app. Apple closed off the ability to take a screenshot of parts of the screen drawn by the system or other apps in iOS 9. – Duncan C Jan 21 '16 at 12:01