-
-
Save jaemyeong/c0e57c5b2396cd69abdc20b97bbf4a41 to your computer and use it in GitHub Desktop.
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
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