/ScrollCounter

ScrollCounter is an iOS framework for getting a nice scrolling animation when transitioning between numbers. This framework is modeled after the animations seen in the Robinhood app.

Primary LanguageSwiftMIT LicenseMIT

ScrollCounter

Version License Platform

Installation

ScrollCounter is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'ScrollCounter'

Usage

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.

Single Digits

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)

Unbounded Numbers

Use a `NumberScrollCounter` to handle an unbounded range of numbers:
// 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)