I'm sandboxing a little timer app. I'm using this cocoapod
This is my code so far:
import UIKit
import CountdownLabel
class ViewController: UIViewController {
@IBOutlet weak var moreBtn: UIButton!
@IBOutlet weak var lessBtn: UIButton!
@IBOutlet weak var gifview: UIImageView!
@IBOutlet weak var countdownLabel: CountdownLabel!
var mins = 25
override func viewDidLoad() {
super.viewDidLoad()
setupCountdown()
updateTimer(min: mins)
}
// MARK: Buttons
@IBAction func startPressed(_ sender: Any) {
countdownLabel.start()
}
@IBAction func lessPressed(_ sender: Any) {
if(mins > 0){
mins = mins - 5
updateTimer(min: mins)
}
}
@IBAction func morePressed(_ sender: Any) {
mins = mins + 5
updateTimer(min: mins)
}
//MARK: Helper Func
func updateTimer(min: Int){
countdownLabel.setCountDownTime(minutes: 60*Double(min))
}
func setupCountdown(){
countdownLabel.textColor = .black
countdownLabel.font = UIFont(name:"Courier", size:UIFont.labelFontSize)
countdownLabel.animationType = .Evaporate
}
}
Now I want to check if the timer is finished (can use this cocoapod built in function: countdownLabel.isFinished() ).
But I have no clue WHERE and HOW I can check this. As an example: if(countdownLabel.isFinished()){countdownLabel.text = "Finished"}
Thanks for your help
This code is not tested, I'm just following the document you posted. Seems like you don't need to check if countdownLabel.isFinished()
, because there is a delegate method for that which will be called as soon as it is finished.
Set up the delegate in func setupCountdown()
:
countdownLabel.countdownDelegate = self
Conform the protocol in your view controller:
class ViewController: UIViewController, CountdownLabelDelegate
Add the delegate method in your view controller:
func countdownFinished() {
// This method will be called when the countdown finishes.
// Do whatever you need here.
}