12345678910111213141516171819202122232425262728293031323334 |
- 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!
-
- }
- }
|