Swiftpack.co - Package - tbaranes/IncrementableLabel

IncrementableLabel

Travis Language CocoaPods Platform License

IncrementableLabel is the easiest way to have incrementable numbers in an UILabel!

Usage

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

Check the sample project for advanced usage

Installation

  • iOS 8.0+
  • tvOS 9.0+

CocoaPods Installation

IncrementableLabel is available on CocoaPods. Just add the following to your Podfile:

pod 'IncrementableLabel'

Swift Package Manager

IncrementableLabel is available on SPM. Just add the following to your Package file:

import PackageDescription

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

Manual Installation

Just drag the Source/*.swift files into your project.

IncrementableLabel properties

var option: IncrementableLabelOptions = .linear

An options indicating how you want to perform the incrementation:

  • linear
  • easeIn
  • easeOut
  • easeInOut
typealias StringFormatter = (Float) -> String
var stringFormatter: StringFormatter?

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

A callback closure which permits a greater control on how the text (attributed or not) is formatted between each incrementation.

var easingRate: Float = 3.0

The rate used when an option is used.

var format: String = "%d"

The format is used to set the text in the label. You can set the format to %f in order to display decimals.

public var currentValue: Double

The label's value during the incrementation

IncrementableLabel methods

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

Starts the incrementation fromValue to toValue. The duration by default will be 0.3

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

Starts the incrementation from the current value to toValue. The duration by default will be 0.3

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

Starts the incrementation from zero to toValue. The duration by default will be 0.3

What's next

  • Any suggestions?

Contribution

  • If you found a bug, open an issue
  • If you have a feature request, open an issue
  • If you want to contribute, submit a pull request

Licence

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

Github

link
Stars: 41
Help us keep the lights on

Dependencies

Used By

Total:

Releases

3.0.0 - Sep 18, 2018

Swift 4.2 and Xcode 10 support

2.0.0 - Nov 28, 2017

Swift 4 and Xcode 9 support

1.2.0 - Sep 11, 2016

API breaking changes

  • Swift 3 support. README is up to date, please report if you find any diffs
  • Some APIs have been updated to be more swifty, check out the README for more information

1.1.0 - May 8, 2016

API breaking changes

  • Use Double instead of Float - #4
  • The completion block is passed as a parameter in the Increment*** methods

Enhancements

  • format and easingRate are now inspectable from the interface builder

1.0.1 - Mar 24, 2016

  • All properties are now public
  • Fixed swift 2.2 warnings