Forked from nunogoncalves/Loading elipsis animation.swift
Last active
June 12, 2021 00:19
-
-
Save hartbeatnt/7e5ba4c0f4ae6ad63467ebd6e4ecc7e4 to your computer and use it in GitHub Desktop.
Setting an ellipsis changing from 1 to 3 dots
This file contains 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
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