Skip to content

Instantly share code, notes, and snippets.

@GnuRant
Last active August 29, 2015 14:10
Show Gist options
  • Save GnuRant/e8b56e58f658b61e3485 to your computer and use it in GitHub Desktop.
Save GnuRant/e8b56e58f658b61e3485 to your computer and use it in GitHub Desktop.
UIImage with color in Swift
//
// UIImage.swift
// ProjectIceCream
//
// Created by Luca D'Incà on 24/11/14.
// Copyright (c) 2014 B3LAB. All rights reserved.
//
import Foundation
import Swift
import UIKit
internal extension UIImage {
/**
Creates and returns a UIImage with a specific color
:param: color, rect: image size
:returns: image with a specific color and size
*/
func imageWithColor(color: UIColor, andRect rect:CGRect) -> UIImage {
UIGraphicsBeginImageContextWithOptions(rect.size, false, 0)
color.setFill()
UIRectFill(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