Skip to content

Instantly share code, notes, and snippets.

@maysamsh
Created June 13, 2020 13:49
Show Gist options
  • Select an option

  • Save maysamsh/8f6086025b1d2044c1c0f8eea1dbb1bc to your computer and use it in GitHub Desktop.

Select an option

Save maysamsh/8f6086025b1d2044c1c0f8eea1dbb1bc to your computer and use it in GitHub Desktop.

Revisions

  1. maysamsh created this gist Jun 13, 2020.
    23 changes: 23 additions & 0 deletions UIView+Ext.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    //
    // UIView+Ext.swift
    // tahrir
    //
    // Created by Maysam Shahsavari on 9/14/19.
    // Copyright © 2019 Maysam Shahsavari. All rights reserved.
    //

    import Foundation
    import UIKit

    extension UIView {
    func snapshot() -> UIImage? {
    UIGraphicsBeginImageContextWithOptions(bounds.size, false, 0.0)
    drawHierarchy(in: CGRect(origin: CGPoint.zero, size: bounds.size), afterScreenUpdates: true)
    if let image = UIGraphicsGetImageFromCurrentImageContext() {
    UIGraphicsEndImageContext()
    return image
    }else{
    return nil
    }
    }
    }