ProgressBarKit
一个可动画的进度条,可以轻松用于显示进度。
要求
- Swift 4.2
- iOS 10 或更高版本
安装
CocoaPods
将以下内容添加到您的 Podfile
中:
pod 'ProgressBarKit'
文档
对于更深入的了解,请参阅 完整文档。
使用方法
开始使用进度条非常简单。只需
- 导入和初始化
- 设置
- 设置进度值
但是...我需要更多自定义。当然,直接到这里!
导入和初始化
import ProgressBarKit
class ViewController: UIViewController {
lazy var progressBar: ProgressBar = {
ProgressBar(trackColour: [.black], barColour: [.purple])
}()
}
初使设置
指定将要作为进度条容器视图的 UIView
并在其中初始化进度条。
progressBar.setup(in: myContainerView)
注意:此方法应只调用一次,并且仅应在 viewDidLayoutSubviews
中调用,以确保 container
已通过自动布局正确布局。
设置进度值
动画进度条从 0
动画到所给的百分比值(十进制数)占进度条容器视图总宽度的比例。
例如,给定 value = 0.75
和 containerView.frame.width
为 100
,进度条只扩展到 0.75 * 100
即 75 个单位宽度。
progressBar.setProgressBarValue(to: 0.75)
注意:应在调用 setupProgressBar(in:)
之后调用此方法,以确保进度条已经初始化。
高级使用
如果你的 设计师 给你的设计增加了一点挑战,或者 你 想要增加一些挑战,不要担心,ProgressBarKit 基本上 已经为你解决了这个问题!
1 使用默认条和轨迹配置的进度条
let bar = ProgressBar(trackColour: [.black], barColour: [.purple])
1 使用自定义条配置的进度条
let barConfig = PBBarConfiguration(
roundingCorners: [.allCorners],
cornerRadii: CGSize(width: 8, height: 8)
)
let bar = ProgressBar(trackColour: [.black], barColour: [.purple], configurations: [.bar: barConfig])
1 使用自定义轨迹配置的进度条
let trackConfig = PBTrackConfiguration(
roundingCorners: [.allCorners],
cornerRadii: CGSize(width: 8, height: 8),
edgeInsets: UIEdgeInsets(top: 2.5, left: 2.5, bottom: 2.5, right: 2.5)
)
let bar = ProgressBar(trackColour: [.black], barColour: [.purple], configurations: [.track: [trackConfig]])
2 个或更多的进度条,使用默认和自定义条配置
let firstTrackConfig = PBTrackConfiguration(
roundingCorners: [.topLeft, .bottomLeft],
cornerRadii: CGSize(width: 8, height: 8),
edgeInsets: UIEdgeInsets(top: 2.5, left: 2.5, bottom: 2.5, right: 2.5)
)
let lastTrackConfig = PBTrackConfiguration(
roundingCorners: [.topRight, .bottomRight],
cornerRadii: CGSize(width: 8, height: 8),
edgeInsets: UIEdgeInsets(top: 2.5, left: 2.5, bottom: 2.5, right: 2.5)
)
// use default values
let otherTrackConfig = PBTrackConfiguration()
// this will display 3 tracks with different configurations, and
// you can have some fun here by adding more configs into the array, and
// watch the magic happens!
let configs = [firstTrackConfig, otherTrackConfig, lastTrackConfig]
let bar = ProgressBar(trackColour: [.black], barColour: [.purple], configurations: [.track: configs])
2 个或更多的进度条,带有渐变轨迹和条配置
// use default values
let defaultTrackConfig = PBTrackConfiguration()
// this will display the track and bar in gradient colours
// you can have some fun here by adding more colours into the array, and
// watch the gradient colour changes!
let gradientTrackColours: [UIColor] = [.black, .white]
let gradientBarColours: [UIColor] = [.red, .purple]
let configs = [defaultTrackConfig, defaultTrackConfig, defaultTrackConfig]
let bar = ProgressBar(trackColour: gradientTrackColours, barColour: gradientBarColours, configurations: [.track: configs])
贡献项目
我们非常愿意接受您为此项目提供的补丁和贡献!请查阅 贡献指南 和 行为准则 了解更多。
版权许可
详见LICENSE文件以获取详细信息