Configurable morphing transitions between text values of a label.

Overview

TOMSMorphingLabel

Configurable morphing transitions between text values of a label. Triggering the animation is as easy as setting the labels text property.

Demo

Screen1

Installation with CocoaPods

TOMSMorphingLabel is available through CocoaPods. To install it, simply add the following line to your Podfile:

Podfile

platform :ios, '7.0'
pod "TOMSMorphingLabel", "~> 0.5"

Usage

Instantiate TOMSMorphingLabel as you would do with an UILabel results in a fully working thus morphing label.

TOMSMorphingLabel *label = [[TOMSMorphingLabel alloc] initWithFrame:CGRectMake(0, 42, self.view.frame.size.width, 42)];
[self.view addSubview:label];

Setting - and particularly changing - the labels text property will automatically morph the labels previous text to the new value.

label.text = @"Swift";

Setting the labels text property using setText:withCompletionBlock will morph the labels as well as triggering the completion block when the animation is finished.

[label setText:@"Swift" withCompletionBlock:^{
  NSLog(@"label.text is now 'Swift'");
}];

Note that the label will execute only one morph transition at a time. If the text value of the label changes during a transition - even if it changes multiple times - the label will invoke a transition to the youngest text value that was set.

Customization

TOMSMorphingLabel provides the possibility to configure the morphing transitions look and feel. The configurable properties are defined as follows:

configurable properties
animationDuration: CGFloat Time that elapses between the setting of a new text value and the end of the morphing transition. Default: 0.37
characterAnimationOffset: CGFloat Spatial propagation speed of the character shrink and alpha effect. Default: 0.25
characterShrinkFactor: CGFloat Factor that the scale of a completely disappeared character is divided by. Default: 4
morphingEnabled: BOOL Defines whether the morphing transition between text values is enabled. Default: YES

Changelog

0.5.1

  • made custom configurable properties accessible by Interface Builder

0.5.0

  • broke a strong reference cycle between CADisplayLink and TOMSMorphingLabel
  • added invokation of the completion block when setting text without animations
  • respect the global [UIView areAnimationsEnabled] state

0.2.5

  • fixed a textColor glitch
  • introduced setText:withCompletionBlock:

0.2.3

  • fixed a bug that caused a crash when setting text to nil

0.2.2

  • added property to disable morphing

0.2.1

  • added support for iOS6

0.2.0

  • added unicode support

0.1.0

  • initial version

Contribution & Contributors

I'd love to see your ideas for improving this library! The best way to contribute is by submitting a pull request or a new Github issue. :octocat:

  • @andrebraga added support for iOS6 in version 0.2.1
  • @stepanhruda added property to disable morphing in version 0.2.2
  • @itouch2 fixed a bug that caused a crash when setting text to nil in version 0.2.3
  • @waynehartman fixed text color-change glitch in version 0.2.5
  • @cyril94440 added setText:withCompletionBlock: in version 0.2.5
  • @wanderwaltz broke a strong reference cycle between CADisplayLink and TOMSMorphingLabel in version 0.5.0
  • @wanderwaltz added invokation of the completion block when setting text without animations in version 0.5.0
  • @wanderwaltz made TOMSMorphingLabel respect the global [UIView areAnimationsEnabled] state in version 0.5.0
  • @fcanas made custom configurable properties accessible by Interface Builder

Author

Tom König @TomKnig

License

TOMSMorphingLabel is available under the MIT license. See the LICENSE file for more info.

Comments
  • Memory leak

    Memory leak

    Hi, I have been testing TOMSMorphingLabel and after some time displaying the label I got memory warnings. I looked at the memory usage and I saw that it was increasing all the time. Although the increase was slow, it ended up giving me a memory warning. Changing the label to a normal UILabel make the problem go away so I think TOMSMorphingLabel is the one that is leaking.

    Anyway, nice work.

    bug help wanted 
    opened by elorz007 4
  • Respect global [UIView areAnimationsEnabled] state.

    Respect global [UIView areAnimationsEnabled] state.

    Hi! I suppose TOMSMorphingLabel should also respect the global areAnimationsEnabled flag of the UIView class so that setting the text like this:

    [UIView performWithoutAnimation: ^{
         tomsLabel.text = @"new text";
    }];
    

    will actually set the text without animation as expected.

    The same goes for the following:

    [UIView setAnimationsEnabled: NO];
    tomsLabel.text = @"new text";
    

    As per documentation for setAnimationsEnabled:, if we disable animations, the currently running animation blocks will continue, but subsequent animation blocks will perform without animation. So checking the [UIView areAnimationsEnabled] state in the isMorphingEnabled getter seems reasonable enough - it won't affect the already started animations but will prevent new ones to start.

    opened by wanderwaltz 3
  • Increase performance

    Increase performance

    Hi, thank you for your awesome lib.

    Do you know how could we increase performance ? When animating 2 labels simultaneously, I get a decrease in frame rate.

    Thanking you in advance.

    opened by cyril94440 3
  • Ported to iOS 6 in two different ways: precise and quick'n'dirty.

    Ported to iOS 6 in two different ways: precise and quick'n'dirty.

    Hello! Ported your awesome component to iOS 6. The changes are actually very simple. Since the new iOS 7 APIs are wrapping existing CoreText functions, it was a matter of simulating what happens behind the curtains.

    The precise method probably incurs in more overhead than the iOS 7 API it attempts to reproduce, but that's what the public APIs allow. The quick'n'dirty method is probably good enough anyway.

    In any circumstance under the simulator the iOS 7 version runs much quicker than the iOS 6 one. That's not a limitation of the overhead: even the QnD version seems slow, and if the foundation guard is taken away and the CoreText method is run unconditionally, the iOS 7 animation speed is the same as before. So there's something weird with (simulated) iOS 6 that's probably not even worth tracking down.

    Anyway, great job, and hope you like my contribution!

    enhancement 
    opened by andrebraga 3
  • Break the strong reference cycle between CADisplayLink and TOMSMorphingLabel.

    Break the strong reference cycle between CADisplayLink and TOMSMorphingLabel.

    Hi, I've implemented a simple solution to the retain cycle problem described in #12. Please tell if that works for you.

    CADisplayLink retains the object set as its target and TOMSMorphingLabel references the display link strongly. This gives a strong reference cycle and TOMSMorphingLabel is never deallocated. This PR adds a helper class named TOMSMorphingLabelWeakWrapper which holds a weak reference to the label and forwards necessary messages to it. This breaks the reference cycle and allows deallocating the label.

    Note that if the weak wrapper's label reference gets nullified due to the label being deallocated, the display link would continue firing its events to the weak wrapper. So it is necessary to properly invalidate the display link in the TOMSMorphingLabel's dealloc.

    opened by wanderwaltz 2
  • Invoke the completion block even if setting text without animations.

    Invoke the completion block even if setting text without animations.

    Hi! I think the completion block of setText:withCompletionBlock: should be called regardless of whether we're setting the text with animations or not.

    When a method with completion block is called, it is kind of assumed that the block will be executed at some point. Otherwise we cannot really know whether it would be called or not without checking the isMorphingEnabled property.

    opened by wanderwaltz 2
  • Fixed text color-change glitch

    Fixed text color-change glitch

    If the text color of the label changes, the animated characters will stay the original color during animations. During the attribution stage, the current color of the text is applied to the attributed text so that that the animated changes are the correct color.

    opened by waynehartman 2
  • Work as button label?

    Work as button label?

    You can use this mod to add the morph to a button label. (I use it for cross-language apps).

    • (void)toggleTextForLabel:label1 { NSLog(@"toggleTextForLabel"); self.label1.text = @" "; //cleans out prior label self.label1.text = textValues[self.idx++];

      dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(4 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [self toggleTextForLabel:self]; [button1 setTitle:self.label1.text forState:UIControlStateNormal]; }); }

    opened by daviddelmonte 2
  •  much slower in my app than in example?

    much slower in my app than in example?

    I saw that the animations are very slow on my iPhone 5 (no problems on my iPhone 7+) and then I tried out the example from the website: those animations ran smoothly as expected.

    opened by sreeji44 1
  • Fix typographical error(s)

    Fix typographical error(s)

    @tomknig, I've corrected a typographical error in the documentation of the TOMSMorphingLabel project. Specifically, I've changed configureable to configurable. You should be able to merge this pull request automatically. However, if this was intentional or if you enjoy living in linguistic squalor, please let me know and create an issue on my home repository.

    opened by orthographic-pedant 1
  • Minor non-breaking interface changes

    Minor non-breaking interface changes

    1. It's more conventional to define external symbols for constant strings.
    2. Adding IBInspectable to the label's properties makes it configurable from interface builder.
    opened by fcanas 1
  • Using system font causes flash of Times New Roman

    Using system font causes flash of Times New Roman

    Xcode 14.1, iOS 16.1

    When the TOMSMorphingLabel is set to use the system font, there is a flash of a serif font (looks like Times New Roman) during the animation. Workaround is setting a custom font.

    opened by clo-dan 1
  • Swift Package Manager Support

    Swift Package Manager Support

    This updates the library to support Swift Package Manager.

    To do this, I rearranged files in accordance with the traditional Swift Package Manager structure:

    Source files reside in a folder named Sources and are scoped per Target. A Swift package can contain several targets, and, as a convention, each target’s code resides in its own subfolder.

    Other notes:

    • Objective-C headers were moved to Sources/TOMSMorphingLabel/include, to be found by SPM by default.
    • The example project's use of Cocoapods was removed and replaced with use of SPM.
    opened by dafurman 0
  • Font.

    Font.

    I need to change font but I see an old font in animations. I fixed it, but can't create pull request.

    -(void) setFont: (UIFont*)font
    {
        [super setFont: font];
    
        @synchronized(self)
        {
            for (NSMutableDictionary* attributionStage in self.attributionStages)
            {
                UIFont* prevFont = attributionStage[NSFontAttributeName];
                attributionStage[NSFontAttributeName] = [UIFont fontWithName: font.fontName
                                                                        size: prevFont.pointSize];
            }
        }
    }
    
    opened by TheHmmka 0
  • Moving TOMSMorphingLabel to OS X.

    Moving TOMSMorphingLabel to OS X.

    Over the last days, I have tried to port this class to OS X. The problem is that CADisplayLink is not available on OS X. Its counterpart, CVDisplayLink should work, but I was not able to get to a working solution.

    opened by mangerlahn 0
Owner
Tom König
Tom König
Animated Mask Label is a nice gradient animated label.

Animated Mask Label Demo Screen Screenshot Demo/Example For demo: $ pod try AnimatedMaskLabel To run the example project, clone the repo, and run pod

Jogendra 19 Dec 13, 2022
Simple countdown UILabel with morphing animation, and some useful function.

CountdownLabel Simple countdown UILabel with morphing animation, and some useful function. features Simple creation Easily get status of countdown fro

keishi suzuki 903 Dec 29, 2022
A morphing UILabel subclass written in Swift.

LTMorphingLabel A morphing UILabel subclass written in Swift. The .Scale effect mimicked Apple's QuickType animation of iOS 8 of WWDC 2014. New morphi

Lex Tang 7.9k Jan 4, 2023
Custom Label to apply animations on whole text or letters.

Ophiuchus Custom Label to apply animations on whole text or letters. Check an article on our blog Inspired by this project on Dribble Installation Coc

Yalantis 885 Dec 2, 2022
A triangle shaped corner label view for iOS written in Swift.

A triangle shaped corner label view for iOS written in Swift. This view is a subclass of UIView. It can be created and customized from the Storyboard

Mukesh Thawani 167 Nov 30, 2022
Animate numeric value while setting new value to label

NumericAnimatedLabel Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installati

Javal Nanda 28 Oct 11, 2021
A faster and more flexible label view for iOS

STULabel is an open source iOS framework for Swift and Objective-C that provides a label view (STULabel), a label layer (STULabelLayer) and a flexible

Stephan Tolksdorf 96 Dec 22, 2022
OdometerLabel - SwiftUI number label with odometer animation

Пример Simulator.Screen.Recording.-.L.iPhone.12.-.2022-01-30.at.16.26.53.mp4

Misnikov Roman 2 Jun 13, 2022
Convert text with HTML tags, links, hashtags, mentions into NSAttributedString. Make them clickable with UILabel drop-in replacement.

Atributika is an easy and painless way to build NSAttributedString. It is able to detect HTML-like tags, links, phone numbers, hashtags, any regex or

Pavel Sharanda 1.1k Dec 26, 2022
Lightweight library to set an Image as text background. Written in swift.

Simple and light weight UIView that animate text with an image.

Lucas Ortis 552 Sep 9, 2022
UILabel subclass, which additionally allows shadow blur, inner shadow, stroke text and fill gradient.

THLabel THLabel is a subclass of UILabel, which additionally allows shadow blur, inner shadow, stroke text and fill gradient. Requirements iOS 4.0 or

Tobias Hagemann 654 Nov 27, 2022
Secret app like text animation

RQShineLabel A UILabel subclass that lets you animate text similar to Secret app. Installation CocoaPods RQShineLabel is available through CocoaPods,

gk 2k Dec 6, 2022
Swift UIView for sliding text with page indicator

SlidingText for Swift Requirements Requires iOS 8 or later and Xcode 6.1+ Installation SlidingText is available through CocoaPods. To install it, simp

Dionysis Karatzas 53 Mar 1, 2022
NumberMorphView a view like label for displaying numbers which animate with transition using a technique called number tweening or number morphing.

NumberMorphView a view like label for displaying numbers which animate with transition using a technique called number tweening or num

Abhinav Chauhan 1.6k Dec 21, 2022
AlertTransition is a extensible library for making view controller transitions, especially for alert transitions.

AlertTransition AlertTransition is a extensible library for making view controller transitions, especially for alert transitions. Overview AlertTransi

Loopeer 570 Nov 29, 2022
DGFadingLabel - A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame

A custom UILabel that fades away the end of your text when text is too large to fit within the label's frame.

donggyu 4 Jun 10, 2022
Animated Mask Label is a nice gradient animated label.

Animated Mask Label Demo Screen Screenshot Demo/Example For demo: $ pod try AnimatedMaskLabel To run the example project, clone the repo, and run pod

Jogendra 19 Dec 13, 2022
Simple countdown UILabel with morphing animation, and some useful function.

CountdownLabel Simple countdown UILabel with morphing animation, and some useful function. features Simple creation Easily get status of countdown fro

keishi suzuki 903 Dec 29, 2022
A morphing UILabel subclass written in Swift.

LTMorphingLabel A morphing UILabel subclass written in Swift. The .Scale effect mimicked Apple's QuickType animation of iOS 8 of WWDC 2014. New morphi

Lex Tang 7.9k Jan 4, 2023
Tools for SwiftUI that helps perform Path and Shape animations, such us morphing circle or shape transformations

SwiftUI+PathAnimations ?? Introduction This packages contains SimilarShape and InterpolatedShape, both can be used to achieve shapes animations with S

Alfredo Delli Bovi 180 Dec 29, 2022