I am following the answer shown here in stackoverflow to implement a countdown timer. The timer text does not flash (works perfectly) when the text is set for a label.
When the same text is set for a button it flashes every time the title is set. How can avoid the button text flashing ?
@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
}
}
This is caused through the setting of the button title text. Just set the type of the button to custom and the flashing should stop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With