Skip to content

A custom animated counting UILabel, written in Swift.

License

Notifications You must be signed in to change notification settings

alexbredy/SACountingLabel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SACountingLabel

language CI Status Version License Platform

SACountingLabel is a highly customizable animated UILabel that can count, inspired by Tim Gostony's UICountingLabel. Originally created as an animated UI component for a game to display scores, SACountingLabel supports the use of various formats such as percentages, currencies and multiple decimal places. It can also be modified to use different animation modes such as linear, ease in, ease out as well as ease in and out.

int

float

custom

Installation

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

pod "SACountingLabel"

And then run:

$ pod install

Manual Installation

To manually install SACountingLabel, simply add SACountingLabel.swift to your project.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Usage

Creating a SACountingLabel is the same as creating a UILabel:

let label = SACountingLabel(frame: CGRect(x: 0, y: 0, width: 100, height: 50))

Or add it to your storyboard or XIB file and set the class type to SACountingLabel instead of UILabel.

This is the general syntax for counting from a start value to an end value for a specified counting and animation style.

label.countFrom(0, to: 100, withDuration: 1.0, andAnimationType: .EaseIn, andCountingType: .Int)

Start Value

The start value is a float value that the counting begins from.

End Value

The end value is a float value where the counting ends.

Duration

The duration is a float value for the length of the animation in seconds.

Animation Type

There are four animation types - linear, ease in, ease out, as well as ease in and ease out.

.Linear

Counts from the start value to the end value at a constant speed.

linear

.EaseIn

Starts counting from the start value slowly and speeds up as it approaches the end value.

easein

.EaseOut

Starts counting from the start value quickly and slows down as it approaches the end value.

easeout

.EaseInOut

Starts counting from the start value slowly, speeds up towards the middle, and slows down again as it approaches the end value.

easeinout

Counting Type

There are three counting types - integer, floating point and custom.

.Int

This will result in counting by integers. 0, 1, 2,..., 100

.Float

This will result in counting using floating points, with a default of 2 decimal places. 0.00, 0.01, 0.02,..., 100

.Custom

This allows you to specify a custom format for the counting. You will have to set the format like this:

label.format = "%.1f%%"

This will result in 0.0%, 0.1%, 0.2%,..., 100%.

Formats like "$%.2f" and "%i points" can be used as well.

License

Copyright (c) 2015 Sudeep Agarwal and Tim Gostony

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

A custom animated counting UILabel, written in Swift.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 59.8%
  • Swift 29.7%
  • Ruby 7.0%
  • Objective-C 3.5%