Day_Count_Memory_Days/anniversary_Project/Tool/CircularProgressBarView.swift
2024-07-15 11:52:15 +08:00

108 lines
2.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// CircularProgressBarView.swift
// anniversary_Project
//
// Created by 16 on 2024/7/10.
//
import Foundation
class CircularProgressBarView: UIView {
private var progressLayer = CAShapeLayer()
private var trackLayer = CAShapeLayer()
var progressColor: UIColor = .blue {
didSet {
progressLayer.strokeColor = progressColor.cgColor
}
}
var trackColor: UIColor = .lightGray {
didSet {
trackLayer.strokeColor = trackColor.cgColor
}
}
var progress: CGFloat = 0 {
didSet {
progressLayer.strokeEnd = progress
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupLayers()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setupLayers()
}
private func setupLayers() {
let circularPath = UIBezierPath(arcCenter: center, radius: bounds.width / 2, startAngle: -CGFloat.pi / 2, endAngle: 3 * CGFloat.pi / 2, clockwise: true)
trackLayer.path = circularPath.cgPath
trackLayer.fillColor = UIColor.clear.cgColor
trackLayer.strokeColor = trackColor.cgColor
trackLayer.lineWidth = 10
trackLayer.lineCap = .round
layer.addSublayer(trackLayer)
progressLayer.path = circularPath.cgPath
progressLayer.fillColor = UIColor.clear.cgColor
progressLayer.strokeColor = progressColor.cgColor
progressLayer.lineWidth = 10
progressLayer.strokeEnd = progress
progressLayer.lineCap = .round
layer.addSublayer(progressLayer)
}
override func layoutSubviews() {
super.layoutSubviews()
trackLayer.frame = bounds
progressLayer.frame = bounds
setupLayers()
}
}
func getTodayWeekday() -> String {
//
let currentDate = Date()
//
let calendar = Calendar.current
// 12
let weekday = calendar.component(.weekday, from: currentDate)
//
let weekdays = ["", "", "", "", "", "", ""]
let weekdayString = weekdays[weekday - 1]
return "\(weekdayString)"
}
func getImageName(for value: Int) -> String {
switch value {
case 1...15:
return "15"
case 16...25:
return "25"
case 26...45:
return "45"
case 46...65:
return "65"
case 66...85:
return "85"
case 86...99:
return "90"
case 100...10000000:
return "100"
default:
return "0"
}
}