Skip to content

boraseoksoon/BRCountDownView

Repository files navigation

BRCountDownView

CI Status Version License Platform

BORING Countdown animated - customizable UI Components.


This is customizable UI-View components to countdown given seconds with countdown animations.
Many properties can be customized including count-down animation by your own!

  • Please replace built-in so boring countdown- animation with your cool stuff :)

Example

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

Requirements

iOS 9.0 +
Swift 3.0 +

Installation

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

pod 'BRCountDownView'

How to use

Since this is straightforwardly simple to use, you can get how to use BRCountDownView by chekcing ViewController.swift in example project.

Step 1. create BRCountDownView programmatically or via storyboard or xib.

By doing so, You can not only create BRCountDown instance, but also customize properties including countdown animation on your own way.
Check sample code below.

  • be careful that BRCountDownView is only supported for fixed size until now.
    (FIXED SIZE : width: 189 / heigh : 74 px)

Below is how to create BRCountDownView programmatically.
(programmatically creating BRCountDownView is highly preffered.)

lazy var countdownView: BRCountDownView = {
  let countdownView = BRCountDownView(timeSeconds: /* 30000 */ 5)
  countdownView.animationStyle = .slideInFromBottom

  /** you can make animate that you would like to perform in this closure if you would.
  To do this, you should change animationStyle property to 'true'.
  */
  //    countdownView.animationStyle = .custom
  //    countdownView.customAnimation = {
  //      [unowned self] animateView, duration in
  //      UIView.animate(withDuration: duration, animations: {
  //        animateView.alpha = 0.0
  //      }, completion:{ finished in
  //        if finished {
  //          animateView.alpha = 1.0
  //        }
  //      })
  //    }

  countdownView.didFinish = {
    [unowned self] (countdownView) -> Void in

    DispatchQueue.main.async {
      self.checkTestLabel.text = "countdown is finished..."
    }

    /** you can again repeat countdown with seconds you want whenever you want. */
    // self.countdownView.repeatCountDown(in: 5)
  }

  countdownView.didRepeat = {
    [unowned self] (countdownView) -> Void in
    
    // it is fired when count-down repeat gets started.
    DispatchQueue.main.async {
      self.checkTestLabel.text = "countdown is repeated..."
    }
  }

  countdownView.didResume = {
    [unowned self] (countdownView) -> Void in
    /**
      do any task here if you need.
    */
    print("didResume!")
  }

  countdownView.didTerminate = {
    [unowned self] (countdownView) -> Void in
    /**
      do any task here if you need.
    */
    print("didTerminate!")
  }

  countdownView.didStop = {
    [unowned self] (countdownView) -> Void in
    /**
      do any task here if you need.
    */
    print("didStop!")
  }

  countdownView.isUserInteractionEnabled = true
  countdownView.didTouchBegin = {
    [unowned self] sender in
    
    print("didTouchBegin!?")
  }

  countdownView.didTouchEnd = {
    [unowned self] sender in
    
    print("didTouchEnd!?")
  }

  return countdownView
}()

Step2. add BRCountDownView instance that programmatically created on a view hierachy that you need.

override func viewDidLoad() {
  super.viewDidLoad()
  // Do any additional setup after loading the view, typically from a nib.

  self.view.addSubview(countdownView)

  // get center.
  countdownView.center = CGPoint(x: self.view.frame.size.width  / 2,
  y: self.view.frame.size.height / 2)
}

Author

Jang seoksoon, [email protected]

License

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