How to make a simple countdown in minutes for swift iOS? -
this question has answer here:
how code simple timer countdown minutes example 5 minute countdown?
like timer apple created. there way download , see xcode project apple apps?
look nstimer simple way this. may not accurate relatively simple. nstimer calls function "update" every second (indicated 1.0 first argument)
@iboutlet var countdownlabel: uilabel! var count = 300 override func viewdidload() { super.viewdidload() var timer = nstimer.scheduledtimerwithtimeinterval(1.0, target: self, selector: selector("update"), userinfo: nil, repeats: true) } func update() { if(count > 0){ let minutes = string(count / 60) let seconds = string(count % 60) countdownlabel.text = minutes + ":" + seconds count-- } }
Comments
Post a Comment