Created
July 17, 2018 20:58
-
-
Save jakehawken/63c5020eb6b4c50302cd3a411c3aa494 to your computer and use it in GitHub Desktop.
Quickly generate images of programmatic colors on the fly.
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 UIImageView | |
| func setImage(withColor color: UIColor) { | |
| image = UIImage.withColor(color, size: bounds.size) | |
| } | |
| } | |
| extension UIImage { | |
| static func withColor(_ color: UIColor, size: CGSize) -> UIImage { | |
| let rect = CGRect(origin: CGPoint.zero, size: size) | |
| UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
| color.setFill() | |
| UIRectFill(rect) | |
| let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()! | |
| UIGraphicsEndImageContext() | |
| return image | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment