A morphing UILabel subclass written in Swift.

Overview

LTMorphingLabel

Travis Language CocoaPods Carthage compatible Accio supported License

A morphing UILabel subclass written in Swift. The .Scale effect mimicked Apple's QuickType animation of iOS 8 of WWDC 2014. New morphing effects are available as Swift extensions.

enum LTMorphingEffect: Int, Printable

.Scale - default

LTMorphingLabel

.Evaporate

LTMorphingLabel-Evaporate

.Fall

LTMorphingLabel-Fall

.Pixelate

LTMorphingLabel-Pixelate

.Sparkle

LTMorphingLabel-Sparkle

.Sparkle is built on top of QuartzCore.CAEmitterLayer. There's also a SpriteKit powered version here.

.Burn

LTMorphingLabel-Burn

.Anvil

LTMorphingLabel-Anvil

SwiftUI

LTMorphingLabelSwiftUI

public var body: some View {
    VStack {
        MorphingText(
            "Awesome Morphing Text",
            effect: .evaporate,
            font: UIFont.systemFont(ofSize: 20),
            textColor: .black,
            textAlignment: .center
        ).frame(maxWidth: 200, maxHeight: 100)
        ...

Requirements

  1. Xcode 12
  2. iOS 9.0+

Installation

Swift Package Manager

  1. File > Swift Packages > Add Package Dependency
  2. Copy & paste https://github.com/lexrus/LTMorphingLabel then follow the instruction

XCFramework

XCFramework is a new option introduced in Xcode 11. You can manually download the pre-compiled LTMorphingLabel.xcframework.zip from the Releases page. Then drag and drop it into your project.

Carthage

  1. Add this line to your Cartfile: github "lexrus/LTMorphingLabel"
  2. Read the official instruction

CocoaPods

  1. Install the latest release of CocoaPods: gem install cocoapods
  2. Add this line to your Podfile: pod 'LTMorphingLabel'
  3. Install the pod: pod install

Accio

  1. Add the following to your Package.swift:
.package(url: "https://github.com/lexrus/LTMorphingLabel.git", .upToNextMajor(from: "0.9.2")),
  1. Next, add LTMorphingLabel to your App targets dependencies like so:
.target(
    name: "App",
    dependencies: [
        "LTMorphingLabel",
    ]
),
  1. Then run accio update.

Usage

  1. Change the class of a label from UILabel to LTMorphingLabel;
  2. Programmatically set a new String to its text property.
  3. To use interactively, call .pause() after changing .text property, and use updateProgress(progress: Float)to update the progress interactively.

Unit tests

Open the project with Xcode then press command + u.

Alternative

Even though this lib was used in a few products on App Store, it’s still an experimental project. Frankly, there’re some nice competitors out there guarantee both compatibility and stability. And the most outstanding one is ZCAnimatedLabel. I’d like to recommend it for production use.

And finally, an Android port.

Third Party Bindings

React Native

You may now use this library with React Native via the module here

License

This code is distributed under the terms and conditions of the MIT license.

Comments
  • Type of expression is ambiguous without more context!

    Type of expression is ambiguous without more context!

    I tried to add some pods like OneSignal and failed to do it so I deleted OneSignal pod and extensions but suddenly LTMorphingLabel got issues. It used to work perfectly for 2 months but after deleting other pods something strange happened screen shot 2017-10-01 at 3 31 53 pm screen shot 2017-10-01 at 3 32 07 pm screen shot 2017-10-01 at 3 33 17 pm

    screen shot 2017-10-01 at 3 48 48 pm

    my pod file looks like this

    # Uncomment this line to define a global platform for your project
    platform :ios, '10.0'
    use_frameworks!
    
    target 'Jaee2' do
    # Comment this line if you're not using Swift and don't want to use dynamic frameworks
      use_frameworks!
    
      # Pods for Jaee2
    pod 'Haneke', '~> 1.0'
    pod 'STLocationRequest'
    pod 'SwiftyJSON'
    pod 'Alamofire', '~> 4.4'
    pod 'PasswordTextField'
    pod 'SkyFloatingLabelTextField', '~> 3.0'
    pod 'SwiftVideoBackground'
    pod 'TIPBadgeManager', '~> 0.3.0'
    pod 'LTMorphingLabel'
    pod 'LocationPickerViewController'
    
    end
    
    opened by AbdulazizAlmohsen 12
  • Prevents a crash when embedding label in a designable view

    Prevents a crash when embedding label in a designable view

    I really like the label, but it keeps crashing the IBDesignables agent when it is programmatically embed it inside an IBDesignable view. The problem is that the IBDesignables agent can't instantiate a display link object to animate the change from empty to whatever other text one provides. Here, I've made 3 changes to get the label to work:

    1. Added the designable tag to the class
    2. Made the animation conditional on the target not being the IB agent. This prevents the above issue with the display link.
    3. Forced the _originText to the new value for the IB agent. This is necessary to get the label to draw the characters correctly. If the value isn't set, then without the animation, the label will be blank (it's previous value).

    I think this is the minimal change required to get the designables behavior, but it might not be the cleanest.

    opened by afdreher 10
  • Use of undeclared type 'LTMorphingLabel'

    Use of undeclared type 'LTMorphingLabel'

    First of all, let me start by saying I love this project ! I have a project with 5-6 pods working on it, lately I've added this pod as well. everything find when i'm adding label on storyboard and setting it to LTMorphingLabel. The problem start when i'm trying to connect the label to code: @IBOutlet private var label: LTMorphingLabel! i'm getting this error, Use of undeclared type 'LTMorphingLabel'. I've tried to import LTMorphingLabel class but it's not recognise as well, of course i've tried to close the project and clean it. did it happen to any of you ? is there any solution for this ? thank you so much. god bless.

    bug help wanted 
    opened by moheny 9
  • Text alignment is strange on IOS 8

    Text alignment is strange on IOS 8

    Hi,

    Congrats for this label, it's very cool. I have a problem. Everything displays properly centered on IOS 7 but is offsetted to the right on iOS 8 . Do you have an idea?

    Thanks

    opened by skware 8
  • Build fails with Carthage and Xcode 12 GM

    Build fails with Carthage and Xcode 12 GM

    I'm attempting to build the latest version of the framework using Carthage and Xcode 12 GM. It seems that it builds correctly in the example project, but when I do it through Carthage, it fails. I can't figure out why, though. It claims it can't find the SwiftUI symbols, but that cannot be the case if it builds in the example project.

    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:35:37: cannot find type 'Context' in scope
    
        public func makeUIView(context: Context) -> UIViewType {
                                        ^~~~~~~
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:42:61: cannot find type 'Context' in scope
    
        public func updateUIView(_ uiView: UIViewType, context: Context) {
                                                                ^~~~~~~
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:12:29: cannot find type 'UIViewRepresentable' in scope
    
    public struct MorphingText: UIViewRepresentable {
                                ^~~~~~~~~~~~~~~~~~~
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:55:31: cannot find type 'View' in scope
    
        static var previews: some View {
                                  ^~~~
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:62:9: unknown attribute 'State'
    
            @State var morphingEnabled = true
            ^
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:63:9: unknown attribute 'State'
    
            @State var textIndex: Double = 0
            ^
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:64:9: unknown attribute 'State'
    
            @State var effectIndex: Double = 0
            ^
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:84:31: cannot find type 'View' in scope
    
            public var body: some View {
                                  ^~~~
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:61:28: cannot find type 'View' in scope
    
        struct PreviewWrapper: View {
                               ^~~~
    
    
    
    ❌  /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabel/SwiftUI/MorphingText.swift:53:31: cannot find type 'PreviewProvider' in scope
    
    struct MorphingText_Previews: PreviewProvider {
                                  ^~~~~~~~~~~~~~~
    
    
    ** ARCHIVE FAILED **
    
    
    The following build commands failed:
    	CompileSwift normal armv7
    	CompileSwiftSources normal armv7 com.apple.xcode.tools.swift.compiler
    	CompileSwift normal arm64
    (3 failures)
    Build Failed
    	Task failed with exit code 65:
    	/usr/bin/xcrun xcodebuild -project /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel/LTMorphingLabelDemo.xcodeproj -scheme LTMorphingLabel -configuration Release -derivedDataPath /Users/AAA/Library/Caches/org.carthage.CarthageKit/DerivedData/12.0_12A7208/LTMorphingLabel/0.8.1 -sdk iphoneos ONLY_ACTIVE_ARCH=NO CODE_SIGNING_REQUIRED=NO CODE_SIGN_IDENTITY= CARTHAGE=YES archive -archivePath /var/folders/s7/m7sqymqs5klgpfl8fk9_ps1h0000gn/T/LTMorphingLabel SKIP_INSTALL=YES GCC_INSTRUMENT_PROGRAM_FLOW_ARCS=NO CLANG_ENABLE_CODE_COVERAGE=NO STRIP_INSTALLED_PRODUCT=NO (launched in /Users/AAA/Development/BBB/CCC/Carthage/Checkouts/LTMorphingLabel)
    
    This usually indicates that project itself failed to compile.
    
    opened by jadar 7
  • Lags in the animation

    Lags in the animation

    Lags in the animation on the latest version 0.6.0.

    ltmorphinglabel 0 6 0 2019-01-30 15_28_42

    And on 0.5.9 version of the library everything was ok.

    ltmorphinglabel 0 5 9

    My class AnimatedLabel added via Storyboard.

    import LTMorphingLabel
    import UIKit
    
    class AnimatedLabel: LTMorphingLabel {
      
      required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        morphingEffect = .evaporate
        morphingDuration = 0.7
      }
    }
    
    opened by yura-voevodin 7
  • Crash in production

    Crash in production

    Hi!

    We really like this library and started using it in production. We're using the .scale effect.

    http://crashes.to/s/3cdb2e84de8

    This is indicates that it is crashing on: s.draw(in: charRect, withAttributes: [ NSFontAttributeName: UIFont.init(name: font.fontName, size: charLimbo.size)!, NSForegroundColorAttributeName: textColor.withAlphaComponent(charLimbo.alpha) ])

    Which I'm not sure what to do about exactly. Any thoughts?

    opened by itchingpixels 7
  • EXC_BAD_ACCESS

    EXC_BAD_ACCESS

    A brand new and pure swift project, followed the instruction to add LTMorphingLabel. Build is fine, but when app is running, XCODE gives EXC_BAD_ACCESS. wondering why...

    opened by HughJia 6
  • How to disable the text effect when init?

    How to disable the text effect when init?

    When my view first loaded, I want to set some value for the label without effect animation. How to make it?

    self.upNumTxt.text = "init val"

    Any suggestions ? Thx

    enhancement 
    opened by neil-wu 4
  • Interface builder font

    Interface builder font

    I've added the files manually to my project (just drag&drop, no framework created) since I have some issues with CocoaPods/Carthage. I have also set the Interface Builder class object of the label to LTMorphingLabel. Did not add module since it's the current one.

    Issue is the label is displayed with some default font instead of the one set in the storyboard. The text also has a big top offset and only the top half is displayed. The label does not have a height constraint in the storyboard, it just has top/bottom/trailing/leading spaces to superview set.

    Thank you for the library, I really appreciate it. Job well done!

    Edit: The text position is almost fixed if I call layoutSubviews() on the label. The baseline is still a few pixels lower than the text using UILabel.

    help wanted 
    opened by emrsn-SebastianVancea 4
  • ♥️ Apps using LTMorphingLabel

    ♥️ Apps using LTMorphingLabel

    I would appriciate it if you tell me that your App is using LTMorphingLabel. Your shinny app may encourage me to make this lib better. And I'll list your App in the README.

    Thanks.

    question 
    opened by lexrus 4
  • SwiftUI Label Width

    SwiftUI Label Width

    Thank you for the great library!

    I have a problem regarding the width of the label went beyond the maxWidth of the frame. Is there any solution to this that I possibly missed?

    image

    The red border is the SwiftUI frame maxWidth.

    opened by Bkhufa 0
  • Weird spacing before starting animation

    Weird spacing before starting animation

    First of all, great library!

    I'll introduce the problem first, check the spacing from the leftmost 3 to the comma, that spacing increases on the first animation and then stays the same. It seems like a small issue but it can be really seen when using the app.

    MorphingLabel bug

    I am using LTMorphingLabel inside a UITableViewCell and the only way I could find to make it work was by adding it as a subview, like this:

    titleLabel?.removeFromSuperview()
    titleLabel = nil
    
    titleLabel = LTMorphingLabel()
    titleLabel!.morphingEnabled = false /// If I don't implement this morphingEnabled false/true the label would animate every time it's shown
    titleLabel!.delegate = self
    titleLabel!.morphingEffect = .evaporate
    titleLabel!.text = formattedNumber /// This is a number formatted to include a comma every 3 characters counting from the right
    titleLabel!.textAlignment = .center
    titleLabel!.font = UIFont(name: "Silka-SemiBold", size: 28)
    titleLabelContainer.addSubview(titleLabel!)
    titleLabel!.morphingEnabled = true
    

    My first thought was maybe some attributedText could be the issue but couldn't find out why this is happening, any help would be appreciated.

    opened by DantePuglisi 2
  • Index out of range Error when Text is empty before the new text will be added.

    Index out of range Error when Text is empty before the new text will be added.

    I got this Error: Thread 1: Fatal error: Index out of range Here:

    func limboOfNewCharacter(
            _ char: Character,
            index: Int,
            progress: Float) -> LTCharacterLimbo {
                
                let currentRect = newRects[index] <---- here i got : Thread 1: Fatal error: Index out of range
                var currentFontSize = CGFloat(
                    LTEasing.easeOutQuint(progress, 0, Float(font.pointSize))
    

    the textlabel was empty (view did load) before i added new text later.

    opened by Skyb0rg 0
  • Incorrect rendering of Khmer script

    Incorrect rendering of Khmer script

    Hi thanks for this awesome lib. Unfortunately, it doesn't render correctly with Khmer script. I attach the video and screenshot for your reference.

    Note: The text above and below should render the same

    Thanks

    artboard

    LabelMorph_s.mov.zip

    opened by kruyvanna 0
Releases(0.9.3)
Owner
Lex Tang
iOS Developer
Lex Tang
KDEDateLabel is an UILabel subclass that updates itself to make time ago's format easier.

KDEDateLabel KDEDateLabel is an UILabel subclass that saves you from refreshing it when using 'time ago' format. Installation You have multiple choice

Kevin Delannoy 117 May 16, 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
A simple designable subclass on UILabel with extra IBDesignable and Blinking features.

JSLabel Demo pod try JSLabel ...or clone this repo and build and run/test the JSLabel project in Xcode to see JSLabel in action. If you don't have Coc

Jogendra 6 May 9, 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
Configurable morphing transitions between text values of a label.

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

Tom König 1.9k Nov 20, 2022
MTLLinkLabel is linkable UILabel. Written in Swift.

# MTLLinkLabel is linkable UILabel. Written in Swift. Requirements iOS 8.0+ Xcode 7.3+ Installation Carthage You can install Carthage with Homebrew. $

Recruit Holdings. Media Technology Lab 74 Jul 1, 2022
UILabel drop-in replacement supporting Hashtags

ActiveLabel.swift UILabel drop-in replacement supporting Hashtags (#), Mentions (@), URLs (http://), Emails and custom regex patterns, written in Swif

Optonaut 4.2k Dec 31, 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
Glitching UILabel for iOS 📺

Glitching UILabel for iOS ?? Created by Lee Sun-Hyoup. Try the sample $ pod try GlitchLabel Requirements iOS 8.0+ Swift 3 Xcode 8 Installation CocoaP

Lee Sun-Hyoup 1k Dec 14, 2022
Incrementable UILabel for iOS and tvOS

IncrementableLabel IncrementableLabel is the easiest way to have incrementable numbers in an UILabel! Usage let myIncrementableLabel = IncrementableLa

Tom Baranes 81 Feb 4, 2022
UILabel with image placed from left or right

SMIconLabel UILabel with possibility to place small icon on the left or on the right side. Take a look at preview image or build sample app to see how

Anatoliy Voropay 94 Apr 27, 2022
A handy class for iOS to use UILabel as a countdown timer or stopwatch just like in Apple Clock App.

MZTimerLabel Purpose MZTimerLabel is a UILabel subclass, which is a handy way to use UILabel as a countdown timer or stopwatch just like that in Apple

Mines Chan 1.6k Dec 14, 2022
A drop-in replacement for UILabel that supports attributes, data detectors, links, and more

TTTAttributedLabel A drop-in replacement for UILabel that supports attributes, data detectors, links, and more TTTAttributedLabel is a drop-in replace

TTTAttributedLabel 8.8k Dec 30, 2022
UILabel replacement with fine-grain appear/disappear animation

ZCAnimatedLabel UILabel-like view with easy to extend appear/disappear animation Features Rich text support (with NSAttributedString) Group aniamtion

Chen 2.3k Dec 5, 2022
Adds animated counting support to UILabel.

UICountingLabel Adds animated counting support to UILabel. CocoaPods UICountingLabel is available on CocoaPods. Add this to your Podfile: pod 'UICount

Tim Gostony 1.9k Dec 1, 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
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
Swift TTTAttributedLabel replacement

Nantes ?? This library is a Swift port/fork of the popular Objective-C library TTTAttributedLabel. Much ❤️ and credit goes to Mattt for creating such

Instacart 1k Dec 22, 2022
NSData Detector with swift

NSDataDetector This playground demonstrates a weird difference in behaviour between Xcodes 12.5.1 and 13.1 regarding NSDataDetector. Try to run it usi

Vinícius Rodrigues de Uzêda 0 Dec 7, 2021