Last active
March 29, 2021 20:39
-
-
Save giovani-pereira-ifood/cfa2aa716ad731c1a6baadc7808fa62b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func createSnapshot(from icon: Icon) -> UIImage { | |
// Create view and add as subview on the window | |
let window: UIWindow = UIApplication.shared.keyWindow ?? UIWindow() | |
let iconView = IconView(icon: icon) | |
window.addSubview(iconView) | |
// Set a default size for all the snapshots | |
iconView.frame = CGRect(origin: .zero, size: dataImageStorageSize) | |
// Take a snapshot | |
let bounds = iconView.bounds | |
let renderer = UIGraphicsImageRenderer(bounds: bounds) | |
let image = renderer.image { _ in | |
iconView.drawHierarchy(in: bounds, afterScreenUpdates: true) | |
} | |
return image | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment