SRCircleProgress

Release CocoaPods Version Swift Compatibility License Twitter

使用 Swift 编写的可自定义圆形进度条。

安装

要求

CocoaPods

SRCircleProgress 可以通过 CocoaPods 获取。要安装它,请将以下内容添加到您的 Podfile 中

pod 'SRCircleProgress'

Swift Package Manager

SRCircleProgress 也可以通过 Swift Package Manager 获取。将 SRCircleProgress 作为依赖项添加到您的 Package.swift 中

.package(url: "https://github.com/Ryu0118/SRCircleProgress", from: "0.2.1")

用法

基本用法如下所示。

let circleProgressView = SRCircleProgress(frame: .zero)
circleProgressView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(circleProgressView)

NSLayoutConstraint.activate([
    circleProgressView.centerXAnchor.constraint(equalTo: view.centerXAnchor),
    circleProgressView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
    circleProgressView.widthAnchor.constraint(equalToConstant: 150),
    circleProgressView.heightAnchor.constraint(equalToConstant: 150),
])

要设置进度条上的进度,

circleProgressView.setProgress(0.5, animated: true)

当前进度由介于 0.0 和 1.0 之间的浮点值表示,包括 0.0 和 1.0。其中 1.0 表示任务完成。默认值为 0.0。小于 0.0 和大于 1.0 的值会被限制到这些极限值。

属性

circleProgressView.progress = 0.6 // Set the progress without animation.
circleProgressView.isReverse = false // Reverse the direction of the color to be filled.
circleProgressView.percent = 60 // Set the percent without animation
circleProgressView.progressLineColor = .systemBlue // The color shown for the portion of the progress view that is filled.
circleProgressView.progressLineWidth = 6 // Specifies the line width of the progress view.
circleProgressView.backgroundLineWidth = 12 // Specifies the line width of the view behind the progress view.
circleProgressView.animationDuration = 0.2 // Specifies the duration of the animation when setProgress(_:animated:) is executed
circleProgressView.progressAngle = .lowerLeftToLowerRight(offset: 0) // Change the shape of the progress view

要更改进度视图的形状,请使用 progressAngle 属性。progressAngle 的可能值为:

enum ProgressAngle {
    case topToTop
    case bottomToBottom
    case lowerLeftToLowerRight(offset: Double = 0)
    case leftToRight(offset: Double = 0)
}
topToTop bottomToBottom
topToTop bottomToBottom
leftToRight(offset = 0) lowerLeftToLowerRight(offset = 0)
leftToRight lowerLeftToLowerRight