RotatingLabel

1.1.0

A label component that animates text changes by scrolling characters.
raymondjavaxx/RotatingLabel

What's New

1.1.0

2023-05-02T23:29:53Z
  • Added tvOS support.
  • RotatingLabel.font is now a non-optional property.

RotatingLabel

RotatingLabel is a label that animates text changes by scrolling characters. The component is designed for presenting numeric values, such as account balances and stock prices, but it can be used for any text, although not ideal.

Installation

To install RotatingLabel using Swift Package Manager, add the following to your Package.swift file:

.package(url: "https://github.com/raymondjavaxx/RotatingLabel.git", from: "1.0.0")

Or, follow the instructions on Adding package dependencies to your app guide.

Usage

Usage is simple. Create a RotatingLabel and set the text property to the value you want to display. When it is time to change the value, use the setText(_:animated:) method to animate it.

let label = RotatingLabel()
label.text = "$100.00"

// ...

label.setText("$155.00", animated: true)

Customization

Animation

You can customize the animation length and timing parameters by setting the animationDuration and animationTimingParameters properties.

label.animationDuration = 0.3
label.animationTimingParameters = UICubicTimingParameters(animationCurve: .easeInOut)

Diffing Function

RotatingLabel uses a diffing function to determine which characters need to be animated. You can use the diffingFunction property to use any of the built-in diffing functions or provide your own.

label.diffingFunction = DiffingFunction { oldValue, newValue in
    var changes: [Operation] = []

    // Your custom diffing logic here

    return changes
}

Dynamic Type

RotatingLabel supports Dynamic Type. The label can automatically adjust its font size when the user changes the content size category. To enable it, set the adjustsFontForContentSizeCategory property to true.

Note: The font must support scaling for this to work. See Scaling Fonts Automatically for more information.

License

RotatingLabel is available under the MIT license. See LICENSE for more info.

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Sat Mar 16 2024 05:56:54 GMT-0900 (Hawaii-Aleutian Daylight Time)