Last active
July 2, 2024 14:55
-
-
Save stakes/de024878ce3cc43d7ee6 to your computer and use it in GitHub Desktop.
UIImage from UIView extension
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
import UIKit | |
extension UIView { | |
func createImage() -> UIImage { | |
let rect: CGRect = self.frame | |
UIGraphicsBeginImageContext(rect.size) | |
let context: CGContextRef = UIGraphicsGetCurrentContext() | |
self.layer.renderInContext(context) | |
let img = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return img | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment