|
//
// UIImageExt.swift
// ExtensionKit
//
// Created by FFIB on 2017/9/14.
// Copyright © 2017年 FFIB. All rights reserved.
//
import UIKit
extension UIImage {
public func scaledImage(_ scale: CGFloat) -> UIImage? {
let rect = CGRect(x: 0, y: 0, width: self.size.width * scale, height: self.size.height * scale).integral
UIGraphicsBeginImageContextWithOptions(rect.size, true, UIScreen.main.scale)
self.draw(in: rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
public static func imageWithColor(_ color: UIColor) -> UIImage {
let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
UIGraphicsBeginImageContext(rect.size)
let context = UIGraphicsGetCurrentContext()
context?.setFillColor(color.cgColor)
context?.fill(rect)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
}
|