Skip to content

Instantly share code, notes, and snippets.

@bittz
Created August 22, 2016 14:41
Show Gist options
  • Save bittz/e51e9ce1ab76238291dcbed649ac13aa to your computer and use it in GitHub Desktop.
Save bittz/e51e9ce1ab76238291dcbed649ac13aa to your computer and use it in GitHub Desktop.
Shorthand for creating empty (black) UIImage.
import UIKit
extension UIImage {
static func placeholder(size: CGSize) -> UIImage {
UIGraphicsBeginImageContext(size)
let context = UIGraphicsGetCurrentContext()
CGContextSetRGBFillColor(context, 0, 0, 0, 1)
CGContextFillRect(context, CGRectMake(0, 0, size.width, size.height))
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment