1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- //
- // CWCustomProgressView.swift
- // ColorfulWallpaper
- //
- // Created by nkl on 2024/9/10.
- //
- import Foundation
- import UIKit
- class CWCustomProgressView: UIView {
- lazy var progressTitle: UILabel = {
- let label = UILabel()
- label.textAlignment = .center
- label.font = UIFont.systemFont(ofSize: 10, weight: .medium)
- label.textColor = .hexColor("#12FFF7")
- label.text = "0%"
- return label
- }()
- lazy var progressView: CWProgressView = {
- let progress = CWProgressView(frame: .init(x: 0, y: 0, width: 36, height: 36), colors: UIColor.hexColor("#B3FFAB"), UIColor.hexColor("#12FFF7"))
- progress.trackColor = .clear
- progress.startAngle = -90
- return progress
- }()
- override init(frame: CGRect) {
- super.init(frame: frame)
- addChildren()
- makeConstraint()
- }
- func addChildren() {
- addSubview(progressTitle)
- addSubview(progressView)
- }
- func makeConstraint() {
- progressView.snp.makeConstraints { make in
- make.edges.equalToSuperview()
- }
- progressTitle.snp.makeConstraints { make in
- make.center.equalToSuperview()
- }
- }
- func set(progress: Double) {
- if progress.isFinite {
- progressTitle.text = "\(Int(progress * 100))%"
- progressView.progress = progress
- } else {
- progressTitle.text = "0%"
- progressView.progress = 0
- }
- }
- required init?(coder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|