Created
July 6, 2020 21:45
-
-
Save BrunoScheltzke/6810bb9d3a26a6876b1aede40f737e4c 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
// | |
// UIColor+Extension.swift | |
// | |
// Created by Bruno Scheltzke on 04/06/20. | |
// Copyright © 2020 Bruno Scheltzke All rights reserved. | |
// | |
import UIKit | |
extension UIColor { | |
func toImage(of size: CGSize) -> UIImage { | |
let rect = CGRect(origin: CGPoint(x: 0, y: 0), size: CGSize(width: size.width, height: size.height)) | |
UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
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