CWCustomProgressView.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //
  2. // CWCustomProgressView.swift
  3. // ColorfulWallpaper
  4. //
  5. // Created by nkl on 2024/9/10.
  6. //
  7. import Foundation
  8. import UIKit
  9. class CWCustomProgressView: UIView {
  10. lazy var progressTitle: UILabel = {
  11. let label = UILabel()
  12. label.textAlignment = .center
  13. label.font = UIFont.systemFont(ofSize: 10, weight: .medium)
  14. label.textColor = .hexColor("#12FFF7")
  15. label.text = "0%"
  16. return label
  17. }()
  18. lazy var progressView: CWProgressView = {
  19. let progress = CWProgressView(frame: .init(x: 0, y: 0, width: 36, height: 36), colors: UIColor.hexColor("#B3FFAB"), UIColor.hexColor("#12FFF7"))
  20. progress.trackColor = .clear
  21. progress.startAngle = -90
  22. return progress
  23. }()
  24. override init(frame: CGRect) {
  25. super.init(frame: frame)
  26. addChildren()
  27. makeConstraint()
  28. }
  29. func addChildren() {
  30. addSubview(progressTitle)
  31. addSubview(progressView)
  32. }
  33. func makeConstraint() {
  34. progressView.snp.makeConstraints { make in
  35. make.edges.equalToSuperview()
  36. }
  37. progressTitle.snp.makeConstraints { make in
  38. make.center.equalToSuperview()
  39. }
  40. }
  41. func set(progress: Double) {
  42. if progress.isFinite {
  43. progressTitle.text = "\(Int(progress * 100))%"
  44. progressView.progress = progress
  45. } else {
  46. progressTitle.text = "0%"
  47. progressView.progress = 0
  48. }
  49. }
  50. required init?(coder: NSCoder) {
  51. fatalError("init(coder:) has not been implemented")
  52. }
  53. }