Skip to content

Instantly share code, notes, and snippets.

@pala
Created May 24, 2015 05:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pala/60cd2aafd6e97fd1e961 to your computer and use it in GitHub Desktop.
Save pala/60cd2aafd6e97fd1e961 to your computer and use it in GitHub Desktop.
UIImage extension
// https://twitter.com/dwineman/status/601853359839006721
// Default arguments are expressions, not constants, evaluated only when necessary.
extension UIImage {
static func emptyImage(size: CGSize, scale: CGFloat = UIScreen.mainScreen().scale) -> UIImage {
UIGraphicsBeginImageContextWithOptions(size, false, scale)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment