Swift: make ellipsis continually retype in label?

2019-09-09 03:23发布

问题:

I have seen no other questions on this concept - Im working in Swift and am doing a sort of loading page where I have a label that says something while the thing loads, similar to Sims. Like: "Checking our sources..."

As a cool animation, I want to have the ellipsis continually "reload" or "retype" so the label goes:

"Checking our sources." -> "Checking our sources.." -> "Checking our sources..." and back again.

I have no idea how to do this and not sure if it qualifies as an animation. How can I constantly alter the text in a label to "animate" my ellipsis? I really would like to do this - is it possible?

回答1:

I have no idea how to do this and not sure if it qualifies as an animation. How can I constantly alter the text in a label to "animate" my ellipsis? I really would like to do this - is it possible?

All you are really describing is a label whose text is modified every so often. Or it doesn't have to be a label; it could just be a view that draws text, and you are redrawing the text every so often. You could easily implement a repeating timer (NSTimer) to do this, or you could use a custom animatable property and let the animation engine do the timing for you.

Took me about a minute to throw this together using an NSTimer, so how hard can it be?

If you like, you can use alternative "ellipsis" characters, or even images: