我有一个标签。我有3根琴弦。我需要在无限循环中以10秒的延迟在相同的标签中显示3个字符串的文本。我如何用swift 3中的简单动画解决这个问题?标签中的文本在swift中的时间延迟3
-1
A
回答
0
这将适用于你的,正确连接你的插座,并在数组中声明这些字符串,并加载定时器更改。
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var label: UILabel!
var array = ["Aaaaaaaaaaa", "Bbbbbbbbbbb", "Ccccccccccc"]
var scrollIndex = 0
override func viewDidLoad() {
super.viewDidLoad()
let timer = Timer.scheduledTimer(timeInterval: 2, target: self, selector: #selector(self.myDelayedFunction), userInfo: nil, repeats: true)
timer.fire()
}
func myDelayedFunction()-> Void {
let count = self.array.count
if scrollIndex == count {
scrollIndex = 0
}
if scrollIndex < count {
if count > 1{
self.label.text = array[scrollIndex]
self.scrollIndex += 1
}
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
+0
FUNC myDelayedFunction() - >空隙{ 令计数= self.array.count 如果scrollIndex ==计数{ scrollIndex = 0 } 如果scrollIndex <计数{ 如果计数> 1 { self.label .text = array [scrollIndex] self.scrollIndex + = 1 }}这一个是正确的。你可以编辑你的答案。 @Subrat Padhi – Tamannah
1
这是我的解决方案。只需将UILabel连接到IBOutlet
class ViewController: UIViewController {
@IBOutlet weak var textLabel: UILabel!
let messages = ["PROFESSIONAL AND BEST LEARNING CENTER","LEARNING TECHNOLOGY AND DESIGN IN A SMART WAY","EXPLORE YOUR SKILLS"]
let delayTime = 10.0
var counter = 0
override func viewDidLoad() {
super.viewDidLoad()
let timer = Timer.scheduledTimer(timeInterval: delayTime, target: self, selector: #selector(changeDisplayedText), userInfo: nil, repeats: true)
timer.fire()
}
func changeDisplayedText() {
textLabel.text = messages[counter % messages.count]
counter += 1
}
}
相关问题
- 1. 在jQuery中延迟的文本文本
- 2. 在Swift 3中显示当前时间的更新标签
- 3. swift中的异步延迟
- 4. Swift中的多重延迟
- 5. 在android中的延迟时间
- 6. 根据文本视图中的文本在swift 3中调整标签?
- 7. CakePHP 2:3:如何在cakephp中添加fadeIn延迟时间。
- 8. WP7中Popup的时间延迟
- 9. 负载测试中的延迟时间
- 10. Micro C OS II中的时间延迟
- 11. 时间延迟(Linux)的/(Windows)中
- 12. 8086中的时间延迟计数器
- 13. Swift:在AppDelegate中设置标签文本
- 14. 如何在我的脚本中加入时间延迟?
- 15. 在Python中添加multipe时间延迟
- 16. 在javascript中使用时间延迟
- 17. 在vb.net中留下时间延迟
- 18. 在C中有时间延迟#
- 19. 我如何自己制作标签更改文本并延迟 - swift?
- 20. 处理环境 - 延迟时间延迟
- 21. Swift 3 - 延迟重复动画
- 22. 如何延迟Swift 3中的for循环?
- 23. 时间延迟,cocos2d的
- 24. jQuery的toggleclass延迟时间
- 25. jQuery的延迟时间
- 26. jQuery的时间延迟
- 27. 基准文件的时间/延迟
- 28. 如何在swift 3中延迟多次动画对象?
- 29. JavaScript时间延迟
- 30. 在matlab中写入GIF文件的延迟时间
您的字符串被声明为“Array”。你会想从它们中删除括号。例如:'let str1:String =“专业和最佳学习中心”' – Adrian
好的我现在怎么办? @阿德里安 – Tamannah