ScrollCounter is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'ScrollCounter'
ScrollCounter is a framework for getting a nice scrolling animation when transitioning between numbers. This framework is modeled after the animations seen in the Robinhood app.
Checkout this Medium article for a high-level look on how ScrollCounter works.
A scroll counter with a single digit can be created and animated in 2 lines:// Initialize a scrolling counter for the standard range between 0-9 (other ranges can be used as well).
let singleDigit = DigitScrollCounter(font: UIFont(name: "Avenir-Black", size: 150)!, textColor: .white, backgroundColor: .black, scrollDuration: 0.3, gradientColor: .black, gradientStop: 0.2)
// Scrolls to the item at the 8th index. For a DigitScrollCounter, this means scroll to the number 8.
singleDigit.scrollToItem(atIndex: 8)
// Initialize a number counter, which is a view composed of `DigitScrollCounter`s.
let numberCounter = NumberScrollCounter(value: 1, scrollDuration: 0.33, decimalPlaces: 2, prefix: "$", suffix: "", font: font.withSize(40), textColor: .white, gradientColor: .black, gradientStop: 0.2)
// Set a new value. This will trigger the animation to show the given value.
numberCounter.setValue(123.45)
This project is based on the original work of Shant Tokatyan, licensed under the MIT License.
The following changes have been made by The Plant:
2025-1-8: Support number separator is supported. 2025-1-8: Change number color and font. For the original project, see [https://github.com/stokatyan/ScrollCounter].