小编Mil*_* H.的帖子

如何在0. Swift停止计时器倒计时

有没有人知道我怎么能告诉计时器在它达到0时停止.现在它继续倒数到零以下.

import UIKit

class ViewController: UIViewController {
    var timerCount = 20
    var timerRunning = false
    var timer = NSTimer()

    @IBOutlet weak var timerLabel: UILabel!

    func Counting() {
        timerCount -= 1
        timerLabel.text = "\(timerCount)"
    }

    @IBAction func startButton(sender: UIButton) {
        if timerRunning == false {
            timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector ("Counting"), userInfo: nil, repeats: true)
            timerRunning = true
        }
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        if …
Run Code Online (Sandbox Code Playgroud)

xcode swift

0
推荐指数
1
解决办法
2349
查看次数

标签 统计

swift ×1

xcode ×1