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

Overview

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.

Comments
  • Fixed time error of counter

    Fixed time error of counter

    currentDate should be setted at the time of the starting(not the time of initializing the CountdownLabel), or the time will be wrong (just a few seconds) after the first time of pausing.

    bug 
    opened by iAugux 2
  • wrong time label

    wrong time label

    countdownLabel = CountdownLabel(frame: centro, minutes: 60) countdownLabel.timeFormat = "hh:ss" countdownLabel.textAlignment = .Center countdownLabel.font = UIFont.boldSystemFontOfSize(60) countdownLabel.animationType = .Evaporate countdownLabel.countdownDelegate = self print(countdownLabel.text)

    print shows 00:01:00 (correct), but label in screen starts from 12:00 and ends in one minute, instead of starting at 01:00

    What am i doing wrong?

    Thanks

    bug 
    opened by MauMaxxa 2
  • Important bug introduce while fixing one day bug

    Important bug introduce while fixing one day bug

    The pull request #29 contains a bug. It doesn't make sense to do the following : var labelText = timeFormat;

    What if my timeFormat is "d'days'" for instance? Please be careful when you accept pull requests.

    Meanwhile I also removed a warning. See issue #39

    opened by pblondin 1
  • Fixed 24H/12H time format due to unforced locale

    Fixed 24H/12H time format due to unforced locale

    When counting down with 12H time format, if counting down less than an hour it would appear as "12:05:00 AM" instead of "00:05:00", even forcing time format to "HH:mm:ss".

    The time format was being ignored since the phone had an unconpatible locale with this time format. Using en_US_POSIX locale fixes this issue.

    Reference from: https://developer.apple.com/library/content/qa/qa1480/_index.html

    opened by ljesus 1
  • countdownLabel.then(0) does not run

    countdownLabel.then(0) does not run

    @suzuki-0000 I have a label counting down from 15.

    countdownLabel.setCountDownTime(15)
            countdownLabel.timeFormat = "ss"
    

    For whatever reason, this method wont run at time = 0

    countdownLabel.then(0) {
                  print("finito")
            }
    

    Whats wierd is I used the exact same code in another project and it ran. I literally copied and pasted but it works in one project, it fails to run in the next. it only works from 15..1. Just not 0

    Why?

    bug 
    opened by otymartin 1
  • Error while using Carthage

    Error while using Carthage

    Hi,

    I can't get to install your framework using Carthage. Any idea why?

    *** Fetching CountdownLabel *** Fetching LTMorphingLabel *** Checking out LTMorphingLabel at "0.2.0" *** Checking out CountdownLabel at "1.1.1" *** xcodebuild output can be found in /var/folders/3x/bfw4yk_d5nz_rcd0b4jcj5b80000gn/T/carthage-xcodebuild.cmPGDT.log *** Building scheme "LTMorphingLabel" in LTMorphingLabelDemo.xcodeproj *** Building scheme "CountdownLabel" in CountdownLabel.xcodeproj ** BUILD FAILED **

    The following build commands failed: PhaseScriptExecution Run\ Script /Users/Pello/Library/Developer/Xcode/DerivedData/CountdownLabel-cczgpbazxfezknchetkgpxakippz/Build/Intermediates/CountdownLabel.build/Release-iphoneos/CountdownLabel.build/Script-89B3C64E1C50780100A02978.sh (1 failure) ld: warning: directory not found for option '-F/Users/Pello/Google Drive/Geek Solutions/Yes You Can Reminder/Yes You Can Reminder/Carthage/Checkouts/CountdownLabel/Frameworks' ld: warning: directory not found for option '-F/Users/Pello/Google Drive/Geek Solutions/Yes You Can Reminder/Yes You Can Reminder/Carthage/Checkouts/CountdownLabel/Frameworks' A shell task (/usr/bin/xcrun xcodebuild -project /Users/Pello/Google Drive/Geek Solutions/Yes You Can Reminder/Yes You Can Reminder/Carthage/Checkouts/CountdownLabel/CountdownLabel.xcodeproj -scheme CountdownLabel -configuration Release -sdk iphoneos ONLY_ACTIVE_ARCH=NO BITCODE_GENERATION_MODE=bitcode CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES clean build) failed with exit code 65: ** BUILD FAILED **

    The following build commands failed: PhaseScriptExecution Run\ Script /Users/Pello/Library/Developer/Xcode/DerivedData/CountdownLabel-cczgpbazxfezknchetkgpxakippz/Build/Intermediates/CountdownLabel.build/Release-iphoneos/CountdownLabel.build/Script-89B3C64E1C50780100A02978.sh (1 failure)

    bug 
    opened by PedroAnibarro1 1
  • Correct the spelling of CocoaPods in README

    Correct the spelling of CocoaPods in README

    This pull requests corrects the spelling of CocoaPods 🤓 https://github.com/CocoaPods/shared_resources/tree/master/media

    enhancement 
    opened by ReadmeCritic 1
  • Fix for another

    Fix for another "The compiler is unable to type-check this expression…

    Fix for another "The compiler is unable to type-check this expression…

    Changed return c * ($0 * $0 * $0 * $0 * $0 + 1.0) + b to

    let m = $0 * $0 * $0 * $0 * $0
    return c * (m + 1.0) + b
    
    opened by iranjith4 0
  • Swift 4 migration

    Swift 4 migration

    Hi,

    I migrated a lot of the code from this library to Swift 4 (#26). Most things are working now, there were a lot of syntax changes in the unit tests, and I was able to fix most of them, but some tests are still failing, so might still need to look into that. Could you perhaps make a swift 4 branch for this?

    Best regards, JoniVR

    enhancement 
    opened by JoniVR 0
  • Fix expression to remove type-check compiler error in Xcode 12.5

    Fix expression to remove type-check compiler error in Xcode 12.5

    Issue

    This issue is getting after Xcode 12.5 update

    The issue is caused by the expression which needed to be break down into sub-expressions

    Using release version : 4.0.1

    The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

    sub-expressions_xcode12-5

    Proposed solution

    Replacing expression:

      return {
            return c * ($0 * $0 * $0 * $0 * $0 + 1.0) + b
      }(t / d - 1.0)
    

    with

       return { (f: Float) in
                return c * (pow(f, 5) + 1.0) + b
        }(t / d - 1.0)
    
    opened by hungHatto 1
  • The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

    The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

    Issue

    This issue is getting after Xcode 12 update.

    The issue is caused by the expression which needed to be break down into sub-expressions

    Using release version : 4.0.1

    Screen Shot 2020-09-18 at 11 37 03 PM

    Buid settings: Screen Shot 2020-09-18 at 11 37 40 PM

    Proposed solution:

    Replacing expression:

    return c * $0 * $0 * $0 * $0 * $0 + b

    with

    return c * ($0 * $0 * $0 * $0 * $0) + b

    opened by mushthak 15
  • Add short format support

    Add short format support

    First of all, thanks for you work. I'm surprised that the short format (m:s vs mm:ss) stopped working after update to v4.0+. Here's my added feature. Not most elegant solution but the whole function requires refactoring (see https://github.com/suzuki-0000/CountdownLabel/pull/40 as well)

    opened by vvit 0
Owner
keishi suzuki
keishi suzuki
A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.

MZTimerLabel Purpose MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple

Mines Chan 1.6k Dec 14, 2022
NumberMorphView a view like label for displaying numbers which animate with transition using a technique called number tweening or number morphing.

NumberMorphView a view like label for displaying numbers which animate with transition using a technique called number tweening or num

Abhinav Chauhan 1.6k Dec 21, 2022
Configurable morphing transitions between text values of a label.

TOMSMorphingLabel Configurable morphing transitions between text values of a label. Triggering the animation is as easy as setting the labels text pro

Tom König 1.9k Nov 20, 2022
UILabel replacement with fine-grain appear/disappear animation

ZCAnimatedLabel UILabel-like view with easy to extend appear/disappear animation Features Rich text support (with NSAttributedString) Group aniamtion

Chen 2.3k Dec 5, 2022
A simple designable subclass on UILabel with extra IBDesignable and Blinking features.

JSLabel Demo pod try JSLabel ...or clone this repo and build and run/test the JSLabel project in Xcode to see JSLabel in action. If you don't have Coc

Jogendra 6 May 9, 2022
Incrementable UILabel for iOS and tvOS

IncrementableLabel IncrementableLabel is the easiest way to have incrementable numbers in an UILabel! Usage let myIncrementableLabel = IncrementableLa

Tom Baranes 81 Feb 4, 2022
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more

TTTAttributedLabel A drop-in replacement for UILabel that supports attributes, data detectors, links, and more TTTAttributedLabel is a drop-in replace

TTTAttributedLabel 8.8k Dec 30, 2022
UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.

THLabel THLabel is a subclass of UILabel, which additionally allows shadow blur, inner shadow, stroke text and fill gradient. Requirements iOS 4.0 or

Tobias Hagemann 654 Nov 27, 2022
UILabel drop-in replacement supporting Hashtags

ActiveLabel.swift UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://), Emails and custom regex patterns, written in Swif

Optonaut 4.2k Dec 31, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022
Glitching UILabel for iOS 📺

Glitching UILabel for iOS ?? Created by Lee Sun-Hyoup. Try the sample $ pod try GlitchLabel Requirements iOS 8.0+ Swift 3 Xcode 8 Installation CocoaP

Lee Sun-Hyoup 1k Dec 14, 2022
KDEDateLabel is an UILabel subclass that updates itself to make time ago's format easier.

KDEDateLabel KDEDateLabel is an UILabel subclass that saves you from refreshing it when using 'time ago' format. Installation You have multiple choice

Kevin Delannoy 117 May 16, 2022
UILabel with image placed from left or right

SMIconLabel UILabel with possibility to place small icon on the left or on the right side. Take a look at preview image or build sample app to see how

Anatoliy Voropay 94 Apr 27, 2022
MTLLinkLabel is linkable UILabel. Written in Swift.

# MTLLinkLabel is linkable UILabel. Written in Swift. Requirements iOS 8.0+ Xcode 7.3+ Installation Carthage You can install Carthage with Homebrew. $

Recruit Holdings. Media Technology Lab 74 Jul 1, 2022
Adds animated counting support to UILabel.

UICountingLabel Adds animated counting support to UILabel. CocoaPods UICountingLabel is available on CocoaPods. Add this to your Podfile: pod 'UICount

Tim Gostony 1.9k Dec 1, 2022
Secret app like text animation

RQShineLabel A UILabel subclass that lets you animate text similar to Secret app. Installation CocoaPods RQShineLabel is available through CocoaPods,

gk 2k Dec 6, 2022
OdometerLabel - SwiftUI number label with odometer animation

Пример Simulator.Screen.Recording.-.L.iPhone.12.-.2022-01-30.at.16.26.53.mp4

Misnikov Roman 2 Jun 13, 2022
A faster and more flexible label view for iOS

STULabel is an open source iOS framework for Swift and Objective-C that provides a label view (STULabel), a label layer (STULabelLayer) and a flexible

Stephan Tolksdorf 96 Dec 22, 2022
A basic countdown app that allows the user to create, edit, and delete events. Each event contains a live countdown timer to a specified date and time.

Event Countdown App (iOS) Created by Lucas Ausberger About This Project Created: January 4, 2021 Last Updated: January 8, 2021 Current Verison: 1.1.1

Lucas Ausberger 1 Jan 8, 2022
A morphing UILabel subclass written in Swift.

LTMorphingLabel A morphing UILabel subclass written in Swift. The .Scale effect mimicked Apple's QuickType animation of iOS 8 of WWDC 2014. New morphi

Lex Tang 7.9k Jan 4, 2023