gpt4 book ai didi

ios - 使用计时器更改 UILabel 的文本

转载 作者:行者123 更新时间:2023-11-28 09:57:41 26 4
gpt4 key购买 nike

我想在一定时间后更改 UILabel 的文本。但在设定的时间后文本不会更改。我该如何解决这个问题?

查看我的代码:

var countDownText = "hello"

override func didMoveToView(view: SKView) {

startButton = UILabel(frame: CGRect(x: 0, y: 0, width: 300, height: 90))
startButton.text = "\(countDownText)"
startButton.center = CGPointMake(view.frame.size.width / 2, view.frame.size.height/2)
startButton.textColor = UIColor.darkGrayColor()
startButton.font = UIFont(name: "Arial", size: 20)
startButton.textAlignment = NSTextAlignment.Center
self.view?.addSubview(startButton)

countDownTimer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("countDownFunc"), userInfo: nil, repeats: true)

}

func countDownFunc(){
theTime++

if(theTime >= 4){
countDownText = "testText"
}

if(theTime >= 8){
spawnEnemys()
startButton.removeFromSuperview()
countDownTimer.invalidate()
}
print(theTime)

}

在此先感谢您的所有帮助 :D

最佳答案

您的countDownFunc 应该是:

func countDownFunc(){
theTime++

if(theTime >= 4){
countDownText = "testText"
startButton.text = countDownText
}

if(theTime >= 8){
spawnEnemys()
startButton.removeFromSuperview()
countDownTimer.invalidate()
}
print(theTime)

}

关于ios - 使用计时器更改 UILabel 的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34462730/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com