Swift version of UICountingLabel
Adds animated counting support to UILabel
.
All necessary classes & methods are written in CountingLabel.swift
, you can just put that file in your project or copy it.
You can add a dependency on CountingLabel
by adding it to your Cartfile
:
github "D-Wang/CountingLabel"
CountingLabel
is subclass of UILabel
, just use it as UILabel
.
Call count(fromValue: CGFloat, toValue: CGFloat, duration: TimeInterval = 2, option: AnimationOption = .linear)
to start the animation.
There are two ways to set the format of your label:
- Set
label.format
like "%.0f". - Implement
CountingLabelValueFormatter
likePercentFormatter
in the demo, and setlabel.valueFormatter
to an instance of that.
valueFormatter
has higher priority than label.format
CountingLabel
support four kind of changing rate, and default is linear. Pass argument option
in method count(fromValue: CGFloat, toValue: CGFloat, duration: TimeInterval = 2, option: AnimationOption = .linear)
to change that.
Avaliable options are:
public enum AnimationOption {
case linear
case easeIn
case easeOut
case easeInOut
}