Last active
March 28, 2020 10:42
-
-
Save DavidPiper94/855f1b0ec5465341adc1aa0f26e0c311 to your computer and use it in GitHub Desktop.
Example code for article about drawing - Reset + Export
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 resetDrawing() { | |
| // 1 | |
| lineArray = [] | |
| setNeedsDisplay() | |
| } | |
| func exportDrawing() -> UIImage? { | |
| // 2 | |
| UIGraphicsBeginImageContext(frame.size) | |
| guard let context = UIGraphicsGetCurrentContext() else { return nil } | |
| // 3 | |
| draw(inContext: context) | |
| // 4 | |
| let image = UIGraphicsGetImageFromCurrentImageContext() | |
| UIGraphicsEndImageContext() | |
| return image | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment