Last active
September 17, 2015 18:40
-
-
Save neilkimmett/6e1d23198b99823ab264 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
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