Skip to content

Instantly share code, notes, and snippets.

@spase84
Created August 27, 2015 04:50
Show Gist options
  • Save spase84/1cf09210a33bb014472e to your computer and use it in GitHub Desktop.
Save spase84/1cf09210a33bb014472e to your computer and use it in GitHub Desktop.
extension UIButton {
func imageWithColor(color: UIColor) -> UIImage {
var rect = CGRectMake(0, 0, self.frame.width, self.frame.height)
UIGraphicsBeginImageContext(rect.size)
var context = UIGraphicsGetCurrentContext()
CGContextSetFillColorWithColor(context, color.CGColor)
CGContextFillRect(context, rect);
var image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment