ProductPromotion
Logo

Swift

made by https://0x3d.site

GitHub - suzuki-0000/CountdownLabel: Simple countdown UILabel with morphing animation, and some useful function.
Simple countdown UILabel with morphing animation, and some useful function. - suzuki-0000/CountdownLabel
Visit Site

GitHub - suzuki-0000/CountdownLabel: Simple countdown UILabel with morphing animation, and some useful function.

GitHub - suzuki-0000/CountdownLabel: Simple countdown UILabel with morphing animation, and some useful function.

CountdownLabel

Swift Carthage Compatible CocoaPods Compatible

Simple countdown UILabel with morphing animation, and some useful function.

sample

features

  • Simple creation
  • Easily get status of countdown from property and delegate.
  • Insert some of function, and completion
  • Style change as usual as UILabel do
  • Morphing animation from LTMorphingLabel.
  • XCTest assertion

Version vs Swift version.

Below is a table that shows which version of what you should use for your Swift version.

Swift version version
4.2 >= 4.0
4.0, 4.1 >= 3.0
3.X >= 2.0
2.3 1.3

Usage

You need only 2 lines.

// from current Date, after 30 minutes.
let countdownLabel = CountdownLabel(frame: frame, minutes: 30) // you can use NSDate as well
countdownLabel.start()

Morphing example

Use animationType. Those effect comes from LTMorphingLabel.

let countdownLabel = CountdownLabel(frame: CGRectZero, time: 60*60)
countdownLabel.animationType = .Pixelate
countdownLabel.start()
morphing effect example
.Burn sample
.Evaporate sample
.Fall sample
.Pixelate sample
.Scale sample
.Sparkle sample

Style

you can directly allocate it as a UILabel property just like usual.

countdownLabel.textColor = .orangeColor()
countdownLabel.font = UIFont(name:"Courier", size:UIFont.labelFontSize())
countdownLabel.start()

sample

Get Status of timer

there's some property for reading status.

countdownLabel.timeCounted      // timer that has been counted
countdownLabel.timeRemaining    // timer's remaining

// example
@IBAction func getTimerCounted(sender: UIButton) {
    debugPrint("\(countdownLabel.timeCounted)")
}

@IBAction func getTimerRemain(sender: UIButton) {
    debugPrint("\(countdownLabel.timeRemaining)")
}

sample

Control countdown

You can pause, start, change time.

// check if pause or not
if countdownLabel.isPaused {
    // timer start
    countdownLabel.start()
} else {
    // timer pause
    countdownLabel.pause()
}
// -2 minutes for ending
@IBAction func minus(btn: UIButton) {
    countdownLabel.addTime(-2)
}
    
// +2 minutes for ending
@IBAction func plus(btn: UIButton) {
    countdownLabel.addTime(2)
}

sample

Insert Function

Using then function or delegate, you can set your function anywhere you like.

// then property 
countdownLabel.then(10) { [unowned self] in
    self.countdownLabel.animationType = .Pixelate
    self.countdownLabel.textColor = .greenColor()
}
countdownLabel.then(5) { [unowned self] in
    self.countdownLabel.animationType = .Sparkle
    self.countdownLabel.textColor = .yellowColor()
}
countdownLabel.start() {
    self.countdownLabel.textColor = .whiteColor()
}

// delegate
func countingAt(timeCounted timeCounted: NSTimeInterval, timeRemaining: NSTimeInterval) {
    switch timeRemaining {
    case 10:
        self.countdownLabel6.animationType = .Pixelate
        self.countdownLabel6.textColor = .greenColor()
    case 5:
        self.countdownLabel6.animationType = .Sparkle
        self.countdownLabel6.textColor = .yellowColor()
    default:
        break
    }
}
func countdownFinished() {
    self.countdownLabel.textColor = .whiteColor()
}

sample

Attributed Text

you can set as attributedText too. note:but morphing animation will be disabled.

countdownLabel.setCountDownTime(30)
countdownLabel.timeFormat = "ss"
countdownLabel.countdownAttributedText = CountdownAttributedText(text: "timer HERE in text", replacement: "HERE")
countdownLabel.start() 

sample

Format

Don't specified over 24 hours or you'll get wrong format. CountdownLabel uses 00:00:00 (HH:mm:ss) as default format. if you prefer using another format, Your can set your time format like below.

countdownLabel.timeFormat = @"mm:ss"

Scheduled

you can set scheduled timer

// after 10 minutes will start a countdown from 20.
let fromDate   = NSDate().dateByAddingTimeInterval(10)
let targetDate = fromDate.dateByAddingTimeInterval(20)
let countdownLabel = CountdownLabel(frame: CGRectZero, fromDate: fromDate, targetDate: targetDate)
countdownLabel.start()

Check Status

some public properties are useful.

countdownLabel.isCounting      // check timer is counting now
countdownLabel.isPaused        // check timer was stopped
countdownLabel.isFinished      // check timer has ended
countdownLabel.morphingEnabled // check morphing is enabled

Requirements

  • iOS 9.0+
  • Swift 2.3+
  • ARC

##Installation

####CocoaPods available on CocoaPods. Just add the following to your project Podfile:

pod 'CountdownLabel'
use_frameworks!

####Carthage To integrate into your Xcode project using Carthage, specify it in your Cartfile:

github "suzuki-0000/CountdownLabel"

Inspirations

License

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

More Resources
to explore the angular.

mail [email protected] to add your project or resources here ๐Ÿ”ฅ.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here ๐Ÿ”.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory