Няма описание

UIImageExt.swift 1.0KB

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // UIImageExt.swift
  3. // ExtensionKit
  4. //
  5. // Created by FFIB on 2017/9/14.
  6. // Copyright © 2017年 FFIB. All rights reserved.
  7. //
  8. import UIKit
  9. extension UIImage {
  10. public func scaledImage(_ scale: CGFloat) -> UIImage? {
  11. let rect = CGRect(x: 0, y: 0, width: self.size.width * scale, height: self.size.height * scale).integral
  12. UIGraphicsBeginImageContextWithOptions(rect.size, true, UIScreen.main.scale)
  13. self.draw(in: rect)
  14. let image = UIGraphicsGetImageFromCurrentImageContext()
  15. UIGraphicsEndImageContext()
  16. return image
  17. }
  18. public static func imageWithColor(_ color: UIColor) -> UIImage {
  19. let rect = CGRect(x: 0.0, y: 0.0, width: 1.0, height: 1.0)
  20. UIGraphicsBeginImageContext(rect.size)
  21. let context = UIGraphicsGetCurrentContext()
  22. context?.setFillColor(color.cgColor)
  23. context?.fill(rect)
  24. let image = UIGraphicsGetImageFromCurrentImageContext()
  25. UIGraphicsEndImageContext()
  26. return image!
  27. }
  28. }