Well, by writing code. This is not a "Teach me how to program site. It's a site where you post questions about specific problems you are having with code you have written.
In short, though do the following:
Record your end time
let endInterval = NSDate.timeIntervalSinceReferenceDate() + secondsToEnd
Create a repeating timer that fires once/second.
Each time it fires, compute the number of seconds remaining to endInterval.
Calculate minutes remaining as
Int((endInterval-nowInterval)/60)
Calculate seconds remaining as
Int(endInterval-nowInterval)%60
There is also the new (to iOS 8) class NSDateComponentsFormatter
, which I've read a little about but haven't used. I believe that will generate formatted timer intervals like hh:mm:ss for you automatically. You'd use the same approach I outlined above, but instead of calculating minutes and seconds yourself, use the NSDateComponentsFormatter
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…