如果我想添加一個函數,就像計時器打到0一樣快。 有沒有人有任何提示?下面是我想要實現它的代碼。將函數添加到計時器
class ViewController: UIViewController {
@IBOutlet weak var Counterlabel: UILabel!
var Nbr = 51
var timerValue = 52
var timer = NSTimer()
override func viewDidLoad() {
super.viewDidLoad()
let timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counter"), userInfo: nil, repeats: true)
}
@IBAction func Btn1(sender: AnyObject) {
Nbr = timerValue - 1
timerValue = timerValue - 1;
}
func Counter(){
Nbr -= 1
Counterlabel.text = "\(Nbr)"
}
}
非常感謝你,真的很感謝:) –