Skip to content

Instantly share code, notes, and snippets.

@BrunoScheltzke
Created July 6, 2020 21:45
Show Gist options
  • Save BrunoScheltzke/6810bb9d3a26a6876b1aede40f737e4c to your computer and use it in GitHub Desktop.
Save BrunoScheltzke/6810bb9d3a26a6876b1aede40f737e4c to your computer and use it in GitHub Desktop.
//
// 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