Skip to content

Instantly share code, notes, and snippets.

@nunogoncalves
Last active June 12, 2021 00:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nunogoncalves/269d59db7afab880888f to your computer and use it in GitHub Desktop.
Save nunogoncalves/269d59db7afab880888f to your computer and use it in GitHub Desktop.
Setting an ellipsis changing from 1 to 3 dots
//Set a NSTimer to update call this function every n seconds to provide desired effect.
var numberOfDots = 3
func applySearchingEffect() {
if let str = label.text {
let range = NSMakeRange(str.length - numberOfDots, numberOfDots)
var string = NSMutableAttributedString(string: str)
string.addAttribute(NSForegroundColorAttributeName, value: UIColor.clearColor(), range: range)
label.attributedText = string
numberOfDots--
if numberOfDots < 0 {
numberOfDots = 3
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment