RadialGradientLayer.swift 1.1 KB

123456789101112131415161718192021222324252627
  1. //
  2. // Converted to Swift 4 by Swiftify v4.2.29618 - https://objectivec2swift.com/
  3. //
  4. // IndefiniteAnimatedView.swift
  5. // SVProgressHUD, https://github.com/SVProgressHUD/SVProgressHUD
  6. //
  7. // Original Copyright (c) 2014-2018 Guillaume Campagna. All rights reserved.
  8. // Modified Copyright © 2018 Ibrahim Hassan. All rights reserved.
  9. //
  10. import QuartzCore
  11. class RadialGradientLayer: CALayer {
  12. var gradientCenter = CGPoint.zero
  13. override func draw(in context: CGContext) {
  14. super.draw(in: context)
  15. let locationsCount = 2
  16. let locations : [CGFloat] = [0.0, 1.0]
  17. let colors : [CGFloat] = [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.75]
  18. let colorSpace = CGColorSpaceCreateDeviceRGB()
  19. if let gradient = CGGradient.init(colorSpace: colorSpace, colorComponents: colors, locations: locations, count: locationsCount) {
  20. let radius = min(bounds.size.width, bounds.size.height)
  21. context.drawRadialGradient(gradient, startCenter: gradientCenter, startRadius: 0, endCenter: gradientCenter, endRadius: radius, options: CGGradientDrawingOptions.drawsAfterEndLocation)
  22. }
  23. }
  24. }