如何使用 NSTimer 进行倒计时? [英] How can I make a countdown with NSTimer?

查看:59
本文介绍了如何使用 NSTimer 进行倒计时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 Swift 使用 NSTimer 进行倒计时?

How can I make a countdown with an NSTimer using Swift?

推荐答案

问题 1:

@IBOutlet var countDownLabel: UILabel!

var count = 10

override func viewDidLoad() {
    super.viewDidLoad()

    var timer = Timer.scheduledTimer(timeInterval: 0.4, target: self, selector: #selector(UIMenuController.update), userInfo: nil, repeats: true)
}

func update() {
    if(count > 0) {
        countDownLabel.text = String(count--)
    }
}

问题 2:

两者都可以.SpriteKit 是您用于场景、运动等的 SDK.Simple View Application 是项目模板.他们不应该冲突

You can do both. SpriteKit is the SDK you use for scene, motion, etc. Simple View Application is the project template. They should not conflict

这篇关于如何使用 NSTimer 进行倒计时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆