Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
import UIKit
extension UIImage {
public convenience init(color: UIColor, size: CGSize) {
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
defer {
UIGraphicsEndImageContext()
}
let context = UIGraphicsGetCurrentContext()
assert(context != nil)
context!.setFillColor(color.cgColor)
context!.fill(CGRect(origin: .zero, size: size))
let image = context!.makeImage()
assert(image != nil)
self.init(cgImage: image!, scale: UIScreen.main.scale, orientation: UIImageOrientation.up)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment