Skip to content

Instantly share code, notes, and snippets.

@DavidPiper94
Last active March 28, 2020 10:42
Show Gist options
  • Select an option

  • Save DavidPiper94/855f1b0ec5465341adc1aa0f26e0c311 to your computer and use it in GitHub Desktop.

Select an option

Save DavidPiper94/855f1b0ec5465341adc1aa0f26e0c311 to your computer and use it in GitHub Desktop.
Example code for article about drawing - Reset + Export
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