Icon.swift 1.0 KB

123456789101112131415161718192021222324252627282930313233
  1. //
  2. // Icon.swift
  3. // ProgressRingExample
  4. //
  5. // Created by Max Konovalov on 22/10/2018.
  6. // Copyright © 2018 Max Konovalov. All rights reserved.
  7. //
  8. import UIKit
  9. import MKRingProgressView
  10. func generateAppIcon(scale: CGFloat = 1.0) -> UIImage {
  11. let size = CGSize(width: 512, height: 512)
  12. let rect = CGRect(origin: .zero, size: size)
  13. let icon = UIView(frame: rect)
  14. icon.backgroundColor = #colorLiteral(red: 1, green: 1, blue: 1, alpha: 1)
  15. let ring = RingProgressView(frame: icon.bounds.insetBy(dx: 66, dy: 66))
  16. ring.ringWidth = 93
  17. ring.startColor = #colorLiteral(red: 1, green: 0.07450980392, blue: 0.3254901961, alpha: 1)
  18. ring.endColor = #colorLiteral(red: 0, green: 0.4784313725, blue: 1, alpha: 1)
  19. ring.progress = 1.0
  20. icon.addSubview(ring)
  21. UIGraphicsBeginImageContextWithOptions(size, true, scale)
  22. icon.drawHierarchy(in: rect, afterScreenUpdates: true)
  23. let image = UIGraphicsGetImageFromCurrentImageContext()!
  24. UIGraphicsEndImageContext()
  25. return image
  26. }