Created
March 2, 2017 19:35
-
-
Save sundeepgupta/29bb23eeb825a1111a8b040caee24ba0 to your computer and use it in GitHub Desktop.
Swift Animating Ellipsis Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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