Created
May 31, 2017 13:55
-
-
Save Savchukv/7a04cb77877ea086f8b508d4b070a6e3 to your computer and use it in GitHub Desktop.
Example extension UIView for creating IOS screenshot
This file contains 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
// | |
// 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