43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
//
|
|
// EGProgressView.swift
|
|
// Crush
|
|
//
|
|
// Created by Leon on 2025/7/26.
|
|
//
|
|
|
|
import UIKit
|
|
|
|
class PhotoBrowseProgressView: UIView {
|
|
var progress: CGFloat = 0 {
|
|
didSet {
|
|
setNeedsDisplay()
|
|
isHidden = progress >= 1
|
|
}
|
|
}
|
|
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
backgroundColor = .clear
|
|
layer.cornerRadius = 5
|
|
clipsToBounds = true
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
fatalError("init(coder:) has not been implemented")
|
|
}
|
|
|
|
override func draw(_ rect: CGRect) {
|
|
guard let context = UIGraphicsGetCurrentContext() else { return }
|
|
let xCenter = rect.width * 0.5
|
|
let yCenter = rect.height * 0.5
|
|
backgroundColor?.setFill()
|
|
UIColor.white.setStroke()
|
|
context.setLineWidth(5)
|
|
context.setLineCap(.round)
|
|
let to = -CGFloat.pi * 0.5 + progress * CGFloat.pi * 2 + 0.05
|
|
let radius = min(rect.width, rect.height) * 0.5 - 10
|
|
context.addArc(center: CGPoint(x: xCenter, y: yCenter), radius: radius, startAngle: -CGFloat.pi * 0.5, endAngle: to, clockwise: false)
|
|
context.strokePath()
|
|
}
|
|
}
|