Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hartbeatnt/7e5ba4c0f4ae6ad63467ebd6e4ecc7e4 to your computer and use it in GitHub Desktop.
Save hartbeatnt/7e5ba4c0f4ae6ad63467ebd6e4ecc7e4 to your computer and use it in GitHub Desktop.
Setting an ellipsis changing from 1 to 3 dots
let animationDelay = 0.5 // tweak this to speed up / slow down animation
var hiddenDots = 3
func animateDots() {
if let str = label.text {
let range = NSRange(location: str.count - hiddenDots, length: hiddenDots)
let string = NSMutableAttributedString(string: str)
string.addAttribute(.foregroundColor, value: UIColor.clear, range: range)
label.attributedText = string
hiddenDots -= 1
if hiddenDots < 0 {
hiddenDots = 3
}
}
DispatchQueue.main.asyncAfter(deadline: .now() + animationDelay) { [weak self] in
self?.animateDots()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment