Skip to content

Instantly share code, notes, and snippets.

@Savchukv
Created May 31, 2017 13:55
Show Gist options
  • Save Savchukv/7a04cb77877ea086f8b508d4b070a6e3 to your computer and use it in GitHub Desktop.
Save Savchukv/7a04cb77877ea086f8b508d4b070a6e3 to your computer and use it in GitHub Desktop.
Example extension UIView for creating IOS screenshot
//
// ExtensionView.swift
//
// Created by Vasiliy Savchuk on 2/6/17.
// Copyright © 2017 All rights reserved.
//
// Usage this snippet:
// yourImageView.image = view.screenshot
import UIKit
extension UIView {
var screenshot: UIImage {
UIGraphicsBeginImageContext(self.bounds.size)
let context = UIGraphicsGetCurrentContext()
self.layer.render(in: context!)
let screenShot = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return screenShot!
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment