Home

Awesome

LTMorphingLabel

Travis Language CocoaPods Carthage compatible Accio supported License

A morphing UILabel subclass written in Swift, originally designed to mimic Apple's QuickType animation in iOS 8 at WWDC 2014.

Table of Contents

Available Effects

.scale (default)

<img src="https://cloud.githubusercontent.com/assets/219689/3491822/96bf5de6-059d-11e4-9826-a6f82025d1af.gif" width="300" height="70" alt="LTMorphingLabel"/>

.evaporate

<img src="https://cloud.githubusercontent.com/assets/219689/3491838/ffc5aff2-059d-11e4-970c-6e2d7664785a.gif" width="300" height="70" alt="LTMorphingLabel-Evaporate"/>

.fall

<img src="https://cloud.githubusercontent.com/assets/219689/3491840/173c2238-059e-11e4-9b33-dcd21edae9e2.gif" width="300" height="70" alt="LTMorphingLabel-Fall"/>

.pixelate

<img src="https://cloud.githubusercontent.com/assets/219689/3491845/29bb0f8c-059e-11e4-9ef8-de56bec1baba.gif" width="300" height="70" alt="LTMorphingLabel-Pixelate"/>

.sparkle

<img src="https://cloud.githubusercontent.com/assets/219689/3508789/31e9fafe-0690-11e4-9a76-ba3ef45eb53a.gif" width="300" height="70" alt="LTMorphingLabel-Sparkle"/>

.sparkle is built on top of QuartzCore.CAEmitterLayer. There is also a SpriteKit-powered version here.

.burn

<img src="https://cloud.githubusercontent.com/assets/219689/3582586/4fb8c52e-0bfe-11e4-9b6f-f070f7f3ab55.gif" width="300" height="70" alt="LTMorphingLabel-Burn"/>

.anvil

<img src="https://cloud.githubusercontent.com/assets/219689/3594949/815cd3e8-0caa-11e4-9738-278a9c959478.gif" width="300" height="70" alt="LTMorphingLabel-Anvil"/>

Usage

UIKit

Since LTMorphingLabel is a drop-in replacement, you can use it like any UILabel by setting its text property, yielding the default effect (.scale):

var exampleLabel = LTMorphingLabel()
exampleLabel.text = "This is a test"

UIKitExample1

Alternatively, it can be used interactively:

var exampleLabel = LTMorphingLabel()
exampleLabel.text = "This is a test"
exampleLabel.pause()

// Call .updateProgress(progress: Float) for interactive animation
// Note: In this case, animation will stop at 45% and will not complete
//       unless called later with 100 as the `progress` float value.
exampleLabel.updateProgress(progress: 45.0)

The effect can be changed by setting the morphingEffect property:

var exampleLabel = LTMorphingLabel()
exampleLabel.text = "This is a test"
exampleLabel.morphingEffect = .burn

UIKitExample2

SwiftUI

To use LTMorphingLabel in SwiftUI, simply declare it and set its text, effect, font, and textColor properties:

public var body: some View {
    VStack {
        MorphingText(
            "This is a test",
            font: UIFont.systemFont(ofSize: 20),
            textColor: .black,
            textAlignment: .center
        )
        .frame(maxWidth: 200, maxHeight: 100)
    }
}

Similar to its use in UIKit, you can also specify the morphing effect manually (if you do not want to use the default .scale effect):

public var body: some View {
    VStack {
        MorphingText(
            "This is a test",
            effect: .burn, // Specify an alternative morphing effect with this line
            font: UIFont.systemFont(ofSize: 20),
            textColor: .black,
            textAlignment: .center
        )
        .frame(maxWidth: 200, maxHeight: 100)
    }
}

LTMorphingLabelSwiftUI

Requirements

Installation

Swift Package Manager

Simply add this library to your package manifest or follow instructions on adding a package dependency using Xcode here.

.package(
    url: "https://github.com/lexrus/LTMorphingLabel.git",
    .branch("master")
)

CocoaPods

Add pod 'LTMorphingLabel' to your Podfile or follow instructions to add dependencies here.

Carthage

Add github "lexrus/LTMorphingLabel" to your Cartfile or follow instructions on adding frameworks here.

XCFramework

A pre-compiled xcframework file is available on the Releases page.

Accio

  1. Add this library to your package manifest (see Swift Package Manager)

  2. Update your target dependencies to include LTMorphingLabel:

.target(
    name: "App",
    dependencies: [
        "LTMorphingLabel",
    ]
),
  1. Run accio update.

Unit Testing

Clone the repo by running git clone https://github.com/lexrus/LTMorphingLabel.git, then open the project with Xcode and press Cmd + U (or, in the menu bar, click Product > Build for > Testing).

Apps Using LTMorphingLabel

Third-Party Ports

Android

The Android port of this library is available here.

React Native

The React Native port of this library is available here.

License

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