【发布时间】:2015-08-19 19:35:21
【问题描述】:
我正在尝试让计时器显示以下内容 - 年:月:周:日:小时:分钟:秒:毫秒。
我不希望它在秒数达到 60 之前显示分钟数,对于小时数天等也是如此。例如:如果它保持在 3 天 4 小时 39 分 3 秒和 43 毫秒,它不应该显示月份或年份,因为到目前为止它们都是 0。
这就是我所拥有的。
@IBOutlet weak var timeLabel: UILabel!
var timerCount = 0
var timerRuning = false
var timer = NSTimer()
func counting() {
timerCount++
timeLabel.text = "\(timerCount)"
}
@IBAction func startTime(sender: UIButton)
{
if timerRuning == false {
timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: ("counting"), userInfo: nil, repeats: true)
timerRuning = true
}
}
@IBAction func finishTime(sender: UIButton)
{
if timerRuning == true {
timer.invalidate()
timerRuning = false
}
}
问题是它只显示秒。我怎样才能让它显示所有其余部分? (就像我上面写的那样。)
【问题讨论】: