Created
August 22, 2016 14:41
-
-
Save bittz/e51e9ce1ab76238291dcbed649ac13aa to your computer and use it in GitHub Desktop.
Shorthand for creating empty (black) UIImage.
This file contains 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 | |
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