

dependencies: [
.package(url: "https://github.com/William-Weng/WWDonutChartView.git", .upToNextMajor(from: "1.2.3"))
]

函数 |
功能 |
setting(lineWidthType:baseLineColor:touchGap) |
设置线宽 / 底线的颜色 / 内缩距离 |
drawing(lineCap:animtionType:) |
绘制动画线条 / 动画类型 |
clean() |
清除线段 |
函数 |
功能 |
duration(in:) |
动画的总时间 (360°) |
informations(in:) |
取得资料相关资讯 |
donutChartView(_:didSelectedIndex:) |
点到哪一个圆环的Index |
donutChartView(_:animation:isStop:isFinished:) |
动画开始 / 停止 / 结束 |
import UIKit
import WWPrint
import WWDonutChartView
final class MyDonutChartView: WWDonutChartView {}
final class ViewController: UIViewController {
@IBOutlet weak var touchedIndexLabel: UILabel!
@IBOutlet weak var donutChartView: MyDonutChartView!
private let infos: [WWDonutChartView.LineInformation] = [
(title: "Red", strokeColor: .red, percent: 0.1),
(title: "Green", strokeColor: .green, percent: 0.3),
(title: "Yellow", strokeColor: .yellow, percent: 0.6),
]
private var lineWidthType: WWDonutChartView.LineWidthType = .custom(56)
override func viewDidLoad() {
super.viewDidLoad()
donutChartView.delegate = self
}
@IBAction func toggleLineWidthType(_ sender: UIBarButtonItem) {
lineWidthType = (sender.tag == 101) ? .custom(56) : .radius
donutChartView.setting(lineWidthType: lineWidthType, baseLineColor: .lightGray, touchGap: 0)
donutChartView.clean()
}
@IBAction func drawAction(_ sender: UIButton) {
let animtionType: WWDonutChartView.AnimtionType
switch lineWidthType {
case .radius: animtionType = .queue
case .custom(_): animtionType = .same
}
donutChartView.drawing(lineCap: .butt, animtionType: animtionType)
}
}
extension ViewController: WWDonutChartViewDelegate {
func duration(in donutChartView: WWDonutChartView) -> Double {
return 1.0
}
func informations(in donutChartView: WWDonutChartView) -> [WWDonutChartView.LineInformation] {
return infos
}
func donutChartView(_ donutChartView: WWDonutChartView, didSelectedIndex index: Int?) {
guard let index = index else { touchedIndexLabel.text = "<null>"; return }
let info = infos[index]
touchedIndexLabel.text = info.title
}
func donutChartView(_ donutChartView: WWDonutChartView, animation: CAAnimation, didStop isStop: Bool, isFinished: Bool) {
wwPrint("\(animation.duration) isStop => \(isStop) => isFinished => \(isFinished)")
}
}