IncrementableLabel

Travis Language CocoaPods Platform License

IncrementableLabel 是在 UILabel 中实现可递增数字的最简单方法!

用法

let myIncrementableLabel = IncrementableLabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))
myIncrementableLabel.incrementFromValue(0, toValue: 100, duration: 1)

查看示例项目了解高级用法

安装

CocoaPods 安装

IncrementableLabel 可通过 CocoaPods 获取。只需将以下内容添加到您的 Podfile

pod 'IncrementableLabel'

Swift Package Manager

IncrementableLabel 可通过 SPM 获取。只需将以下内容添加到您的 Package 文件

import PackageDescription

let package = Package(
    dependencies: [
        .Package(url: "https://github.com/recisio/IncrementableLabel.git", majorVersion: 1)
    ]
)

手动安装

只需将 Source/*.swift 文件拖到您的项目中。

IncrementableLabel 属性

var option: IncrementableLabelOptions = .linear

一个选项,指示您希望如何执行递增

typealias StringFormatter = (Float) -> String
var stringFormatter: StringFormatter?

typealias AttributedTextFormatter = (Float) -> NSAttributedString
var attributedTextFormatter: AttributedTextFormatter?

一个回调闭包,允许更好地控制在每次递增之间文本(带属性或不带属性)的格式化方式。

var easingRate: Float = 3.0

使用 option 时的速率。

var format: String = "%d"

格式用于设置标签中的文本。您可以将格式设置为 %f 以显示小数。

public var currentValue: Double

递增期间标签的值

IncrementableLabel 方法

func increment(fromValue: Float, toValue: Float, duration: Float = 0.3, fromColor: UIColor? = nil, toColor: UIColor? = nil, completion: IncrementableLabelCompletion? = nil)

启动从 fromValuetoValue 的递增,文本颜色从 fromColor 更改为 toColor。默认持续时间为 0.3

func incrementFromCurrentValue(toValue: Float, duration: Float = 0.3, fromColor: UIColor? = nil, toColor: UIColor? = nil, completion: IncrementableLabelCompletion? = nil)

启动从当前值到 toValue 的递增。默认持续时间为 0.3

func incrementFromZero(toValue: Float, duration: Float = 0.3, fromColor: UIColor? = nil, toColor: UIColor? = nil, completion: IncrementableLabelCompletion? = nil)

启动从零到 toValue 的递增。默认持续时间为 0.3

下一步

贡献

许可证

IncrementableLabel 在 MIT 许可证下可用。有关更多信息,请参阅 LICENSE 文件。