Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Objective-C: How to animate "Loading..." text on a UILabel

In my app I need to display a "Loading" text in an UILabel, repeatedly as follows:

Loading Loading. Loading.. Loading... Loading Loading. Loading.. Loading...

How can I do it? Any suggestion, please?

like image 914
iOS dev Avatar asked Jan 28 '26 05:01

iOS dev


1 Answers

Swift 4.2

You can simply use Timer.

    var timer: Timer?

    titleLabel.text = "Loading ."

    timer = Timer.scheduledTimer(withTimeInterval: 0.55, repeats: true) { (timer) in
        var string: String {
            switch self.titleLabel.text {
            case "Loading .":       return "Loading .."
            case "Loading ..":      return "Loading ..."
            case "Loading ...":     return "Loading ."
            default:                return "Loading"
            }
        }
        self.titleLabel.text = string
    }

    // Stop the timer 
    // timer?.invalidate()

Result

Result Screen

like image 162
Den Avatar answered Jan 29 '26 20:01

Den



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!