Files
raspberry/iOS/Wallet/Sources/Resources/View/Chart/ResourcesViewChart.swift
2022-05-27 20:21:01 +03:00

100 lines
3.4 KiB
Swift

//
// ResourcesViewChart.swift
// PayCash
//
// Created by Igor on 09.03.2021.
// Copyright © 2021 AM. All rights reserved.
//
import UIKit
class ResourcesViewChartDraw: UIView {
var progress: CGFloat = 0 { didSet { setNeedsDisplay() } }
override func draw(_ rect: CGRect) {
let lineWidth: CGFloat = 12
func configure(path: UIBezierPath, color: UIColor) {
path.lineWidth = lineWidth
path.lineCapStyle = .round
color.setStroke()
path.stroke()
}
configure(path: .init(
arcCenter: .init(x: frame.width/2, y: frame.width/2),
radius: frame.width/2 - lineWidth/2,
startAngle: -3*CGFloat.pi/2 + CGFloat.pi/6,
endAngle: CGFloat.pi/2 - CGFloat.pi/6,
clockwise: true
), color: Asset.marble.color)
configure(path: .init(
arcCenter: .init(x: frame.width/2, y: frame.width/2),
radius: frame.width/2 - lineWidth/2,
startAngle: -3*CGFloat.pi/2 + CGFloat.pi/6,
endAngle: CGFloat.pi/2 - CGFloat.pi/6 - (1 - progress)*(2*CGFloat.pi - CGFloat.pi/3),
clockwise: true
), color: Asset.deepWater.color)
}
}
class ResourcesViewChartDrawV2: UIView {
var progress: CGFloat = 0 {
didSet {
setNeedsDisplay()
}
}
let lineWidth: CGFloat = 5
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = .clear
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func draw(_ rect: CGRect) {
configure(path: UIBezierPath(
arcCenter: .init(x: frame.width/2, y: frame.width/2),
radius: frame.width/2 - lineWidth/2,
startAngle: -3*CGFloat.pi/2 + CGFloat.pi/6,
endAngle: CGFloat.pi/2 - CGFloat.pi/6,
clockwise: true
), color: Asset.marble.color)
if progress < 0.01 { progress = 0.01 }
configure(path: UIBezierPath(
arcCenter: .init(x: frame.width/2, y: frame.width/2),
radius: frame.width/2 - lineWidth/2,
startAngle: -3*CGFloat.pi/2 + CGFloat.pi/6,
endAngle: CGFloat.pi/2 - CGFloat.pi/6 - (1 - progress)*(2*CGFloat.pi - CGFloat.pi/3),
clockwise: true
), color: progress > 0.05 ? Asset.deepWater.color : Asset.brick.color)
}
func configure(path: UIBezierPath, color: UIColor) {
path.lineWidth = lineWidth
path.lineCapStyle = .round
color.setStroke()
path.stroke()
}
}
class ResourcesViewChart: CommonViewCustom {
@IBOutlet private weak var drawView: ResourcesViewChartDraw!
@IBOutlet private weak var progressLbl: UILabel!
@IBOutlet private weak var titleLbl: UILabel!
@IBOutlet private weak var textLbl: UILabel!
var progress: CGFloat = 0 { didSet { drawView.progress = progress } }
var progressText: String? {
didSet { progressLbl.attributedText = progressText?.attributed(style: .medium, size: 24, color: Asset.textGranite.color, alignment: .center) }
}
var title: String? { didSet { titleLbl.attributedText = title?.attributed(style: .medium, size: 12, color: Asset.textGranite.color, alignment: .center) } }
var text: String? { didSet { textLbl.attributedText = text?.attributed(style: .medium, size: 14, color: Asset.textGranite.color, alignment: .center) } }
}