Вы можете попробовать таймер
var countTimer:Timer!
var counter = 36
//
в viewDidLoad
установить его
self.countTimer = Timer.scheduledTimer(timeInterval: 1 ,
target: self,
selector: #selector(self.changeTitle),
userInfo: nil,
repeats: true)
func changeTitle()
{
if counter != 0
{
button.setTitle("SEND SMS AGAIN IN \(counter)", for: .normal)
counter -= 1
}
else
{
countTimer.invalidate()
button.backgroundColor = // set any color
}
}
//
ИЛИ использоватьБлок таймера IOS 10+
//
let sendSMSAgainNumberOfTime: UIButton = {
let button = UIButton(type: .system)
button.backgroundColor = .black
button.layer.cornerRadius = 7
button.setTitle("SEND SMS AGAIN IN 36", for: .normal)
button.setTitleColor(.white, for: .normal)
button.titleLabel?.font = UIFont(name: "open sans", size: 16)
// timer block exists from ios 10 +
if #available(iOS 10.0, *) {
Timer.scheduledTimer(withTimeInterval: 1, repeats: true, block: { (t) in
if(button.tag != 37)
{
button.setTitle("SEND SMS AGAIN IN \(36-button.tag)", for: .normal)
button.tag += 1
}
else
{
t.invalidate()
button.backgroundColor = // set any color
}
})
} else {
// Fallback on earlier versions
}
return button
}()