A custom UILabel that acts as a time counter, counting up or down and formatting the string to hours, minutes, seconds and milliseconds. Designed to accept a value in milliseconds that is then displayed it in a time friendly format. Currently the controls supports up-to a maximum value of 99 hours 59 minutes 59 seconds and 999 milliseconds, which should be enough for most uses. The control automatically removes any leading zeros and centralises the result. It also supports different fonts for each unit division.
Installing with CocoaPods
If you're unfamiliar with CocoaPods there is a great tutorial here to get you up to speed.
In Terminal navigate to the root of your project.
Run 'touch Podfile' to create the Podfile.
Open the Podfile using 'open -e Podfile'
Add the pod
TTCounterLabelto your Podfile.
platform :ios pod 'TTCounterLabel'
Open your app's
.xcworkspacefile to launch Xcode and start using the control!
Installing manually from GitHub
- Download the
TTcounterLabel.mfiles and add them to your Xcode project.
#import TTCounterLabel.hwherever you need it.
- Follow the included sample project to get started.
Running the sample project
Check out the sample project included in the repository. Just open the '.xcworkspace' file in the Sample folder and the project should build correctly.
- Add a normal Label control to your storyboard
- In the Identity Inspector for the label, set the Custom Class to TTCounterLabel
- Implement the TTCounterLabelDelegate interface to receive callbacks from the label
- Set the label's countDirection to one of kCountDirectionDown or kCountDirectionUp
- call [label setStartValue:<time in ms>] to set the start value (important in the case of a downward counter).
- Use [label start] and [label stop] to start and stop the counter.
- The counter calls back on the contdownDidEnd method on the class that implements TTCounterLabelDelegate. The source parameter will be a reference to the label object that fired the event.
Distributed under the MIT License.