Skip to content

Instantly share code, notes, and snippets.

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

What would you like to do?
import UIKit
extension UIImage {
public convenience init(color: UIColor, size: CGSize) {
UIGraphicsBeginImageContextWithOptions(size, true, 0.0)
defer {
let context = UIGraphicsGetCurrentContext()
assert(context != nil)
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.