I have aUILabel
which has attributed text set like
Good morning \n Alex
It shows as 2 lines in UILabel
. I want to show this and after few seconds remove the Good morning part and just show the Alex part.
Is this possible to do? Please help me
I have aUILabel
which has attributed text set like
Good morning \n Alex
It shows as 2 lines in UILabel
. I want to show this and after few seconds remove the Good morning part and just show the Alex part.
Is this possible to do? Please help me
You can create a NSTimer
- Documentation for number of seconds and after that timer fires, you would simply change the text of the UILabel
textLabel.attributedText = "Alex"
inside of the completion block of the NSTimer
You could use GCD
let delayInSeconds = 4.0
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + delayInSeconds) {
textLabel.attributedText = "Alex"
}
Use this function and pass your delay and update the attributed text:-
func delay(_ delay: Double, closure: @escaping () -> Void) {
DispatchQueue.main.asyncAfter(
deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
}
func updateAttributedText() {
delay(1) {
self.textLabel.attributedText = NSAttributed(string: "Alex")
}
}