Giter Club home page Giter Club logo

swiftyglyphs's Introduction

SwiftyGlyphs

Version License Platform

Animate individual glyphs of a UILabel without needing the heavy Core Text library. Turn the glyphs into images for most cases. Optionally you can also turn glyphs into SKSpriteNodes if you need extra animation capabilities via SKActions.

Features

  • Generate array of gylph images from a UILabel.
  • Preserves font color, style and spacing as individual transparent png's.
  • Option to generate SKSpriteNode glyphs instead for SKActions.

Usage

Animate an array of characters.

alt tag

import UIKit
import SwiftyGlyphs

class ViewController: UIViewController {
   var swiftyLabel = SwiftyGlyphs(fontName: "MarkerFelt-Wide", size:24)

   override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)

      swiftyLabel.text = "SwiftyGlyphs!"
      swiftyLabel.setLocation(self.view, pos: CGPoint(x:0,y:100))
      swiftyLabel.centerTextToView()

      exampleAnimation(swiftyLabel.getGlyphs())
   }

   func exampleAnimation(glyphs:[Glyph]) {
      var delay = 1.0
      for glyph in glyphs {
         UIView.animateWithDuration(0.5, delay: delay, options: [.Repeat, .CurveEaseInOut, .Autoreverse], animations: {
            glyph.imgView.center.y = 140
            glyph.imgView.transform = CGAffineTransformMakeRotation(CGFloat(-M_PI))
         }, completion: nil)
         delay += 0.01
     }
   }
}

SpriteKit Usage

Requres an SKView. With this example I added a UIView the storyboard UIViewController and then customized it in the side panel as an SKView. Then dragged over the IBOutlet.

alt tag

import UIKit
import SpriteKit
import SwiftyGlyphs

class ViewController: UIViewController {

   @IBOutlet weak var skview: SKView!
   var spriteLabel = SpriteGlyphs(fontName: "Copperplate-Light", size:24)

   override func viewDidAppear(animated: Bool) {
      super.viewDidAppear(animated)

      spriteLabel.text = "SpriteKit Baby!!"
      spriteLabel.setLocation(skview, pos: CGPoint(x:0,y:30))
      spriteLabel.centerTextToView()

      spriteKitAnimation(spriteLabel.getSprites())
    }
    
    func spriteKitAnimation(sprites:[SKSpriteNode]) {

      let moveSeq = SKAction.sequence([
         SKAction.moveBy(CGVector(dx:30,dy:0), duration: 0.3),
         SKAction.moveBy(CGVector(dx:0,dy:30), duration: 0.5),
         SKAction.moveBy(CGVector(dx:-30,dy:0), duration: 0.2),
         SKAction.moveBy(CGVector(dx:0,dy:-30), duration: 0.3),
         SKAction.moveBy(CGVector(dx:0,dy:30), duration: 0.3),
         SKAction.moveBy(CGVector(dx:0,dy:-30), duration: 0.4),
      ])
      moveSeq.timingMode = .EaseIn

      let rotationSeq = SKAction.sequence([
         SKAction.rotateToAngle(CGFloat(M_PI), duration: 1),
         SKAction.rotateToAngle(0, duration: 2.3),
      ])
      rotationSeq.timingFunction = snappyEaseOut

      var delay = 0.0
      for glyphSprite in sprites {
         let delaySeq = SKAction.sequence([Act.waitForDuration(delay),rotationSeq])
         let group = SKAction.group([moveSeq,delaySeq])
         group.timingMode = .EaseInEaseOut
         let repeatAction = SKAction.repeatActionForever(group)
         glyphSprite.runAction(repeatAction)
         delay += 0.01
      }
   }

   func snappyEaseOut (t:Float) -> Float {
      return (t == 1.0) ? t : 1.0 - pow(2.0, -10.0 * t)
   }
}

Installation

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

pod "SwiftyGlyphs"
Manual Installation (copy 4 files)

SwiftyGlyphs.swift, ImageExtractor.swift, Glyph.swift, SpriteGlyphs.swift

Author & licence

Woodie Dovich, [email protected]

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

swiftyglyphs's People

Contributors

snowpunch avatar serhii-londar avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

warpling

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.