Skip to content

wieweb/CountingView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CountingView

Carthage compatible Swift 2.2

Inspired by UICountingLabel this is a swift version of an animated counting label.

Example

##Usage

To start the counting animation just call startCounting

label.startCounting(destinationValue: 100)

// with all available properties
label.startCounting(0,
		destinationValue: 1000,
      	duration: 3,
          method: .Linear,
	       progress: { value in
   		   	print(value)
      	},
      	completion: {
      		print("complete")
    	})

Format

By setting format you can also add a text.

label.format = "%@ Value"

Alternatively you can provide a NSNumberFormatter to define the format of the animated number.

    let formatter = NSNumberFormatter()
    formatter.minimumIntegerDigits = 5
    formatter.maximumFractionDigits = 0;
    formatter.numberStyle = .DecimalStyle
    formatter.groupingSeparator = "."
    
    linealLabel.numberFormatter = formatter

Custom AnimatedView

If you want to create your own animated views use the CountAnimatorclass.

let animator = CountAnimator(startValue: startValue, destinationValue: destinationValue, duration: duration, method: method)

animator.startCount({ value in
	if let formatedValue = self.numberFormatter.stringFromNumber(value) {
		self.text = String.localizedStringWithFormat(self.format, formatedValue)
		if let progress = progress {
			progress(value: value)
		}
	}
}, completion: {
	if let completion = completion {
		completion()
	}
})

This class also provide startCount with a progressand completionclosure.

Installation

Carthage

Add the following line to your Cartfile.

####Swift 2.3

github "wieweb/CountingView" ~> 1.1

####Swift 3.0

github "wieweb/CountingView" "swift3.0"

Then run carthage update.

Manually

Just drag and drop the two .swift files in the CountingView folder into your project.

Todo

  • Counting Button

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published