Skip to content

Instantly share code, notes, and snippets.

@neilkimmett
Last active September 17, 2015 18:40
Show Gist options
  • Save neilkimmett/6e1d23198b99823ab264 to your computer and use it in GitHub Desktop.
Save neilkimmett/6e1d23198b99823ab264 to your computer and use it in GitHub Desktop.
import UIKit
public func draw(size: CGSize, drawBlock: (CGContext) -> ()) -> UIImage? {
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
defer {
UIGraphicsEndImageContext()
}
guard let context = UIGraphicsGetCurrentContext() else {
return nil
}
drawBlock(context)
return UIGraphicsGetImageFromCurrentImageContext()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment