Skip to content

Instantly share code, notes, and snippets.

@wtsnz
Created September 15, 2015 02:04
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 wtsnz/fa14a2118e20a4bc440c to your computer and use it in GitHub Desktop.
Save wtsnz/fa14a2118e20a4bc440c to your computer and use it in GitHub Desktop.
import Foundation
import UIKit
extension UIImage {
class func imageForColor(color: UIColor) -> UIImage {
let rect = CGRectMake(0, 0, 1, 1)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, color.CGColor);
CGContextFillRect(context, rect);
let image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment