Skip to content

Instantly share code, notes, and snippets.

@sundeepgupta
Created March 2, 2017 19:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sundeepgupta/29bb23eeb825a1111a8b040caee24ba0 to your computer and use it in GitHub Desktop.
Save sundeepgupta/29bb23eeb825a1111a8b040caee24ba0 to your computer and use it in GitHub Desktop.
Swift Animating Ellipsis Loader
class LoadingLabel: UILabel {
var timer: Timer?
let states = [".", "..", "..."]
var currentState = 0
func start() {
stop(withText: "")
timer = Timer.scheduledTimer(timeInterval: 0.3, target: self, selector: #selector(update), userInfo: nil, repeats: true)
timer?.fire()
}
func stop(withText text: String) {
timer?.invalidate()
timer = nil
self.text = text
}
@objc func update() {
text = states[currentState]
currentState = (currentState + 1) % states.count
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment