Last active
September 19, 2017 17:36
-
-
Save ahmetgeymen/b4bc5fe1fed8711da8e0a2d4eb405185 to your computer and use it in GitHub Desktop.
Extension to UIImage which returns an image filled with given solid color and given size.
This file contains hidden or 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
import UIKit | |
extension UIImage { | |
static func imageWithColor(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) -> UIImage? { | |
UIGraphicsBeginImageContext(size) | |
if let context = UIGraphicsGetCurrentContext() { | |
context.setFillColor(color.cgColor) | |
context.fill(CGRect(origin: .zero, size: size)) | |
} | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment