You should better show whole method including your code, showing all relevant parts of the class would be better.
I assume your code exists (except the IBOutlet declaration) exists in an action method.
One thing you should know is that all actual view updates happen at a certain time after the action method is terminated.
So, any updates done while executing the action method would have no effect.
A simple advise: never call `sleep` or any other waiting functions.
That might make your app irresponsible and can be a cause that your app would not be approved.
If you want process something with delay, you can use `Timer`.
An example:
var buttonUpdatingTimer: Timer?
var updatingCount: Int = 0
@IBAction func buttonPressed(_ button: UIButton) {
if let oldTimer = buttonUpdatingTimer {
oldTimer.invalidate()
}
self.updatingCount = 0
buttonUpdatingTimer = Timer(fire: Date(), interval: 3, repeats: true) {timer in
let count = self.updatingCount
if count > self.nTokens {
self.buttonUpdatingTimer?.invalidate()
self.buttonUpdatingTimer = nil
self.generateButton.isHighlighted = false
return
}
self.updatingCount = count + 1
let x = (Double(count)/Double(self.nTokens)) * 100
print(button.isHighlighted)
self.generateButton.isHighlighted = true
self.generateButton.setTitle("\(x) %", for: .highlighted)
self.generateButton.titleLabel!.font = UIFont.systemFont(ofSize: 20)
}
RunLoop.main.add(buttonUpdatingTimer!, forMode: .default)
}