Skip to content

Instantly share code, notes, and snippets.

@jaemyeong jaemyeong/UIImageExtensions.swift Secret
Last active Mar 18, 2018

Embed
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.