Last active
August 29, 2015 14:10
-
-
Save GnuRant/e8b56e58f658b61e3485 to your computer and use it in GitHub Desktop.
UIImage with color in Swift
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
// | |
// 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