- Notifications
You must be signed in to change notification settings - Fork23
👻 A UILabel subclass that adds a typewriting animation effect
License
MIT, MIT licenses found
Licenses found
wibosco/GhostTypewriter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
AUILabel subclass that adds a typewriting animation effect - as if a 👻 was typing it directly on your user's device!
GhostTypewriter was inspired by the following posthere.
To integrateGhostTypewriter into your Xcode project using CocoaPods, specify it in yourPodfile:
source'https://github.com/CocoaPods/Specs.git'platform:ios,'10.0'pod'GhostTypewriter'
Then, run the following command:
$ pod install
CocoaPods 1.1.1+ is required to build
GhostTypewriter.
Swift Package Manager is a dependency manager built into Xcode.
If you are using Xcode 11 or higher, go toFile -> Add Packages... and enter package repository URLhttps://github.com/wibosco/GhostTypewriter into the search bar, then follow the instructions.
TypewriterLabel is a subclass ofUILabel and where the animation (magic) happens. It works by taking advantage of theattributedText property on the label and changing the properties of the text content to gradually expose the text using an animation similar to what you get on a mechanical typewriter.
ATypewriterLabel instance when added as a subview will hide it's content.
Starting the animation will cause the content of the label to be reveal one character at a time.
How quickly each character is revealed is controlled by setting the
typingTimeIntervalproperty.
There are two ways to start an animation: with and without a completion closure.
With a completion closure:
import GhostTypewriter@IBActionfunc startAnimationButtonPressed(_ sender:Any){ titleLabel.startTypewritingAnimation{ //Implement your completion closure body here...}}
Without a completion closure:
import GhostTypewriter@IBActionfunc startAnimationButtonPressed(_ sender:Any){ titleLabel.startTypewritingAnimation()}
Stopping an animation causes the characters that have been revealed to remain as is and no new characters being revealed.
import GhostTypewriter@IBActionfunc stopAnimationButtonPressed(_ sender:Any){ titleLabel.stopTypewritingAnimation()}
Resetting an animation causes all characters to be hidden.
import GhostTypewriter@IBActionfunc resetAnimationButtonPressed(_ sender:Any){ titleLabel.resetTypewritingAnimation()}
It's important to note that resetting anTypewriterLabel instance does not cause the animation to restart instead you need to callrestartTypewritingAnimation().
Restarting an animation causes all characters to be hidden and for the animation to begin from the start again.
There are two ways to start an animation: with and without a completion closure.
Without a completion closure:
import GhostTypewriter@IBActionfunc restartAnimationButtonPressed(_ sender:Any){ titleLabel.restartTypewritingAnimation()}
With a completion closure:
import GhostTypewriter@IBActionfunc restartAnimationButtonPressed(_ sender:Any){ titleLabel.restartTypewritingAnimation{ //Implement your completion closure body here...}}
Completing an animation causes all characters to instantly be revealed.
import GhostTypewriter@IBActionfunc completeAnimationButtonPressed(_ sender:Any){ titleLabel.completeTypewritingAnimation()}
By defaultTypewriterLabel reveals the content as it animates however this can be changed to hiding the content by setting theanimationStyle property to.hide:
import GhostTypewriteroverridefunc viewDidLoad(){ super.viewDidLoad() titleLabel.animationStyle=.hide}
animationStyleis defaulted to.reveal
By defaultTypewriterLabel animates from character index0 ton-1 however this can be changed to go from charcter indexn-1 to0 by setting theanimationDirection to.backward:
import GhostTypewriteroverridefunc viewDidLoad(){ super.viewDidLoad() titleLabel.animationDirection=.backward}
animationDirectionis defaulted to.forward.
Each character of aTypewriterLabel instance is revealed at a pace set by thetypingTimeInterval property.
typingTimeInterval defaults to0.1 second.
import GhostTypewriteroverridefunc viewDidLoad(){ super.viewDidLoad() titleLabel.typingTimeInterval=0.3}
It's important to note that setting/changingtypingTimeInterval after an animation has been started, has no affect on the timing of that animation.
AsTypewriterLabel is contained in a pod, when using it with storyboards you will need to set theModule field toGhostTypewriter.
Version2.0.0 ofGhostTypewriter contains breaking changes.
cancelTypewritingAnimation()now useresetTypewritingAnimation().cancelTypewritingAnimation(clearText: true)now useresetTypewritingAnimation().cancelTypewritingAnimation(clearText: false)now usestopTypewritingAnimation().
GhostTypewritercomes with anexample project to provide more details than listed above.
Please open anew Issue here if you run into a problem specific to GhostTypewriterLabel, have a feature request, or want to share a comment.
Pull requests are encouraged and greatly appreciated! Please try to maintain consistency with the existing code style. If you're considering taking on significant changes or additions to the project, please communicate in advance by opening a new Issue. This allows everyone to get onboard with upcoming changes, ensures that changes align with the project's design philosophy, and avoids duplicated work.
About
👻 A UILabel subclass that adds a typewriting animation effect
Topics
Resources
License
MIT, MIT licenses found
Licenses found
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors4
Uh oh!
There was an error while loading.Please reload this page.
