use*_*776 2 uibutton uilabel ios swift
我按照stackoverflow中显示的答案来实现倒数计时器.为标签设置文本时,计时器文本不会闪烁(完美地工作).
当为按钮设置相同的文本时,每次设置标题时它都会闪烁.如何避免按钮文字闪烁?
@IBOutlet weak var countDownTimer: UILabel!
@IBOutlet weak var countDownTimerButton: UIButton!
var count = 120
override func viewDidLoad() {
super.viewDidLoad()
var _ = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(update), userInfo: nil, repeats: true)
// Do any additional setup after loading the view.
}
func update() {
if(count > 0){
let minutes = String(count / 60)
let seconds = String(count % 60)
countDownTimer.text = minutes + ":" + seconds // Setting text for label (Works perfectly)
let text = minutes + ":" + seconds
countDownTimerButton.setTitle(text, for: .normal) // Setting text for button, (Text flashes everytime it is set)
count -= 1
}
}
Run Code Online (Sandbox Code Playgroud)