Skip to content

Instantly share code, notes, and snippets.

@yickling
Created December 21, 2016 09:31
Show Gist options
  • Save yickling/676942ff60abc969574c6a75f86ff04c to your computer and use it in GitHub Desktop.
Save yickling/676942ff60abc969574c6a75f86ff04c to your computer and use it in GitHub Desktop.
Placeholder UIImage in Swift
func generatePlaceholderImageWithColor(_ color: UIColor) -> UIImage? {
let rect : CGRect = CGRect(x: 0, y: 0, width: 1, height: 1)
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
color.setFill()
UIRectFill(rect)
let image : UIImage = UIGraphicsGetImageFromCurrentImageContext()!
UIGraphicsEndImageContext()
return image
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment