Last active
January 12, 2021 12:34
-
-
Save kylehowells/e5f9198e723018373a1d8a27952011f5 to your computer and use it in GitHub Desktop.
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
| extension UIColor { | |
| func kh_renderImage() -> UIImage? { | |
| let size = CGSize(width:1, height: 1) | |
| return UIGraphicsImageRenderer(size: size).image(actions: { (rendererContext) in | |
| let context = UIGraphicsGetCurrentContext() | |
| self.setFill() | |
| context?.fill(CGRect(origin: .zero, size: size)) | |
| }) | |
| } | |
| } | |
| // Usage: | |
| //button.setBackgroundImage(UIColor.blue.kh_renderImage(), for: UIControl.State.normal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment